I am 开发者_如何学Cusing this tutorial here and when I add this section of code directly into my OnCreate class I get the above error
DataBaseHelper myDbHelper = new DataBaseHelper(null);
myDbHelper = new DataBaseHelper(this);
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
} catch(SQLException sqle){
throw sqle;
}
I am still pretty new so any help and pointing in the right direction is most appreciated.
You have to pass DataBaseHelper
a valid Context
. You'll probably want to pass it the main Activity (or this
if it is in the Activity).
To get more information about the exception, try "chaining" the thrown Error with the caught IOException:
catch (IOException ioe) {
throw new Error("Unable to create database", ioe);
}
That should show you the SQLException
that is being thrown.
精彩评论