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.
@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
******************/
@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.
> 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.
> @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
> ******************/
> @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.
> check your table creation statements within onCreate()
> On May 5, 11:29 pm, AJ <warhawk...@charter.net> 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.
> > @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.
AJ wrote: > Here's the full onCreate() function. Seems like standard SQL syntax > to me?
What was the error you got? You can get the error log from adb logcat or DDMS. It should tell you what SQLite or Android did not like.
> public void onCreate(SQLiteDatabase db) { > db.execSQL("CREATE TABLE IF NOT EXISTS " > + DATABASE_TABLE_USER > + " (userID INT PRIMARY KEY, name VARCHAR(40),"
D'oh! Wow, can't believe I missed that... my first time using SQLite
here, in case that wasn't already obvious. :p
The database gets created now. Thank you very much! A few follow-up
questions:
- Where do these error logs you speak of live? What exactly are adb
logcat and DDMS?
- How does a DATE datatype get converted from MySql into SQLite?
Text? Blob?
- sqlite.org is down at the moment, so I'll search around for other
examples, but what are the main differences between MySQL and SQLite
regarding INSERT statements?
You're awesome - thanks again!
On May 8, 7:23 am, Mark Murphy <mmur...@commonsware.com> wrote:
> - How does a DATE datatype get converted from MySql into SQLite? > Text? Blob?
I can't speak for MySQL. With respect to SQLite, I've seen both string representations (e.g., ISO 8601) and integer representations (Unix epoch/seconds-since-1970).
> - sqlite.org is down at the moment
It's working for me here.
> so I'll search around for other > examples, but what are the main differences between MySQL and SQLite > regarding INSERT statements?
I haven't played much with MySQL in ages. INSERT is pretty close to ANSI SQL, though, IIRC.
The link above is quite useful......nothing to lose .......zero investment
.......and spending a little time you can start earning atleast 25 dollars
easily to begin with and thereafter that its upto your efforts. Best to try.
cheeeeeers
On Sun, May 10, 2009 at 1:50 AM, AJ <warhawk...@charter.net> wrote:
> D'oh! Wow, can't believe I missed that... my first time using SQLite
> here, in case that wasn't already obvious. :p
> The database gets created now. Thank you very much! A few follow-up
> questions:
> - Where do these error logs you speak of live? What exactly are adb
> logcat and DDMS?
> - How does a DATE datatype get converted from MySql into SQLite?
> Text? Blob?
> - sqlite.org is down at the moment, so I'll search around for other
> examples, but what are the main differences between MySQL and SQLite
> regarding INSERT statements?
> You're awesome - thanks again!
> On May 8, 7:23 am, Mark Murphy <mmur...@commonsware.com> wrote:
> > AJ wrote:
> > > Here's the full onCreate() function. Seems like standard SQL syntax
> > > to me?
> > What was the error you got? You can get the error log from adb logcat or
> > DDMS. It should tell you what SQLite or Android did not like.
> > > public void onCreate(SQLiteDatabase db) {
> > > db.execSQL("CREATE TABLE IF NOT EXISTS "
> > > + DATABASE_TABLE_USER
> > > + " (userID INT PRIMARY KEY, name
> VARCHAR(40),"