开发者

GetReadableDatabase error android

开发者 https://www.devze.com 2023-02-03 18:52 出处:网络
I created a DBTest class SQLiteOpenHelper Then I called this from my main UI. It crashes when I hit the DB.GetReadableDatabase () and the log is no help, just says null pointer, but I don\'t know wh

I created a DBTest class SQLiteOpenHelper

Then I called this from my main UI.

It crashes when I hit the DB.GetReadableDatabase () and the log is no help, just says null pointer, but I don't know where to look.

Everything works if I use

SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

Same database

Here is the Class for the helper and below the error:

   public class DBTest extends SQLiteOpenHelper {

            private static String DB_NAME = "DB";

            private SQLiteDatabase myDataBase; 

            private final Context myContext;

            public DBTest(Context context) {

                super(context,   DB_NAME, null, 1);
                this.myContext = context;
            }

            @Override
            public void onCreate(SQLiteDatabase db) {
                // TODO Auto-generated method stub
开发者_开发知识库
            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                // TODO Auto-generated method stub

            }
    }

Below is where the error happens:

public class Main extends Activity 
{

    DataBaseHelper db = new DataBaseHelper(null);
    static SQLiteDatabase Db;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SQLiteDatabase Db;

        DBTest db1 = new DBTest(null);

        Db = db1.getReadableDatabase(); <<<  blow up here


        }
}


DBTest db1 = new DBTest(this.getApplicationContext());

Context can't be null

0

精彩评论

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

关注公众号