开发者

Uncaught handler: thread main exiting due to uncaught exception

开发者 https://www.devze.com 2023-03-03 08:34 出处:网络
I am 开发者_如何学Cusing this tutorial here and when I add this section of code directly into my OnCreate class I get the above error

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消