Here's the full onCreate() function. Seems like standard SQL syntax
to me?
**********
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS "
+ DATABASE_TABLE_USER
+ " (userID INT PRIMARY KEY, name VARCHAR(40),"
+ " birthdate DATETIME,"
+ " weight INT(3), heightInches INT, "
+ " smoking BOOLEAN DEFAULT 'FALSE',"
+ " school BOOLEAN DEFAULT 'FALSE', "
+ " reading BOOLEAN DEFAULT 'FALSE',"
+ " religion BOOLEAN DEFAULT 'FALSE',"
+ " dating BOOLEAN DEFAULT 'FALSE');");
db.execSQL("CREATE TABLE IF NOT EXISTS "
+ DATABASE_TABLE_ACH
+ " (achID INT PRIMARY KEY AUTO-INCREMENT, "
+ " category VARCHAR(40),"
+ " subCategory VARCHAR(40),"
+ " icon VARCHAR(40), "
+ " name VARCHAR(40), "
+ " description VARCHAR(200),"
+ " hasProgress BOOLEAN, "
+ " goal INT,"
+ " points INT);");
db.execSQL("CREATE TABLE IF NOT EXISTS "
+ DATABASE_TABLE_USER_ACH
+ " (achID INT PRIMARY KEY, "
+ " hasProgress BOOLEAN, "
+ " goal INT, "
+ " progress INT, "
+ " isCompleted BOOLEAN, "
+ " dateCompleted DATETIME, "
+ " CONSTRAINT FK_achID FOREIGN KEY (achID)
REFERENCES Ach, "
+ " CONSTRAINT FK_hasProgress FOREIGN KEY
(hasProgress)
REFERENCES Ach, "
+ " CONSTRAINT FK_goal FOREIGN KEY (goal)
REFERENCES Ach);");
}
**********
On May 6, 3:37 am, swarup <[email protected]> wrote:
> check your table creation statements within onCreate()
>
> On May 5, 11:29 pm, AJ <[email protected]> wrote:
>
> > Hello - our dev team is looking into utilizing an SQLite DB as a means
> > to store data within our application. We've been following the
> > official dev guide's NotePad tutorial (http://d.android.com/guide/
> > tutorials/notepad/notepad-ex1.html) to accomplish this, but we're
> > stuck on Step 2: the preliminary creation of the database itself. We
> > aren't even concerned with inserting into and retrieving from the DB
> > yet.
>
> > Basically, we re-purposed the NoteDbAdapter.java file (renamed to
> > simply DbAdapter.java) to work with our main activity, called
> > LifeVault. When an instance of the DbAdapter class created within
> > LifeVault.java calls the "open()" function within DbAdapter.java,
> > however, the Android emulator just crashes and displays a message
> > along the lines of "the process has stopped working and needs to
> > close."
>
> > The code doesn't have any compilation errors, and it's based on the
> > code from the official dev guide, so we're pretty perplexed as to why
> > this happens.
>
> > /******************
> > DbAdapter.java
> > *******************/
> > package com.android.lifevault;
>
> > import android.content.Context;
> > import android.database.SQLException;
> > import android.database.sqlite.SQLiteDatabase;
> > import android.database.sqlite.SQLiteOpenHelper;
> > import android.util.Log;
>
> > public class DbAdapter {
>
> > private static final String TAG = "DbAdapter";
> > private DatabaseHelper mDbHelper;
> > private SQLiteDatabase mDb;
>
> > private static final String DATABASE_NAME = "FVDB";
> > private static final String DATABASE_TABLE_USER = "User";
> > private static final String DATABASE_TABLE_ACH = "Ach";
> > private static final String DATABASE_TABLE_USER_ACH = "User_Ach";
> > private static final int DATABASE_VERSION = 1;
>
> > private final Context mCtx;
>
> > private static class DatabaseHelper extends SQLiteOpenHelper {
>
> > DatabaseHelper(Context context) {
> > super(context, DATABASE_NAME, null, DATABASE_VERSION);
> > }
>
> > �...@override
> > public void onCreate(SQLiteDatabase db) {
> > // Our "db.execSQL" statements for creating the three tables
> > live here
> > }
>
> > �...@override
> > public void onUpgrade(SQLiteDatabase db, int oldVersion, int
> > newVersion) {
> > Log.w(TAG, "Upgrading database from version " + oldVersion
> > + " to "
> > + newVersion + ", which will destroy all old
> > data");
> > db.execSQL("DROP TABLE IF EXISTS User_Ach");
> > db.execSQL("DROP TABLE IF EXISTS Ach");
> > db.execSQL("DROP TABLE IF EXISTS User");
> > onCreate(db);
> > }
> > }
>
> > /**
> > * Constructor - takes the context to allow the database to be
> > * opened/created
> > */
> > public DbAdapter(Context ctx) {
> > this.mCtx = ctx;
> > }
>
> > /**
> > ** Open the database - Here's where things get screwy.
> > **/
> > public DbAdapter open() throws SQLException {
> > mDbHelper = new DatabaseHelper(mCtx);
> > mDb = mDbHelper.getWritableDatabase();
> > return this;
> > }
>
> > public void close() {
> > mDbHelper.close();
> > }}
>
> > /******************
> > END DbAdapter.java
> > ******************/
>
> > /******************
> > LifeVault.java
> > ******************/
> > package com.android.lifevault;
>
> > import com.android.lifevault.DbAdapter;
> > import android.app.Activity;
> > import android.os.Bundle;
> > import android.view.View;
>
> > public class LifeVault extends Activity {
>
> > private DbAdapter mDbHelper;
>
> > @Override
> > public void onCreate(Bundle icicle) {
> > super.onCreate(icicle);
> > mDbHelper = new DbAdapter(this);
> > mDbHelper.open(); // <--------- Program crashes here
> > setContentView(R.layout.main);
>
> > /**The rest of the code**/
>
> > }}
>
> > /********************
> > END LifeVault.java
> > ********************/
>
> > - Am I using the Context class incorrectly?
> > - Am I missing a library that the app needs to recognize the
> > getWritableDatabase() funciton?
>
> > Those are my two best guesses. I'm so close I can taste it!
> > Hopefully someone can help me see this answer that's probably right in
> > front of my face. Thank you; the help is greatly appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---