getWritableDb失败——java.io.File android.content.Context.getDatabasePath(java.lang.String)'

new SQLiteOpenHelper()时,Context不能是Application。如果传入Application,会java.io.File android.content.Context.getDatabasePath(java.lang.String)' on a null object reference

 

Process: com.ader.testgreendao, PID: 27131
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getDatabasePath(java.lang.String)' on a null object reference
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:367)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:313)
        at org.greenrobot.greendao.database.DatabaseOpenHelper.getWritableDb(DatabaseOpenHelper.java:59)
        at com.ader.testgreendao.database.DaoManager.(DaoManager.java:31)
        at com.ader.testgreendao.database.DaoManager.getInstance(DaoManager.java:48)
        at com.ader.testgreendao.business.test.CreateDaoActivity.getData(CreateDaoActivity.java:49)
        at com.ader.testgreendao.business.test.CreateDaoActivity.onClick(CreateDaoActivity.java:38)
        at android.view.View.performClick(View.java:6663)
        at android.view.View.performClickInternal(View.java:6635)
        at android.view.View.access$3100(View.java:794)
        at android.view.View$PerformClick.run(View.java:26199)
        at android.os.Handler.handleCallback(Handler.java:907)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
    

你可能感兴趣的:(Android)