2014-03-13 72 views
0

我已經創建了一個應用程序,並測試了它的Android API16和API19和它的作品,但是當我測試API18在啓動Android的 - 版本

03-13 11:17:25.884: E/AndroidRuntime(2678): FATAL EXCEPTION: main 
03-13 11:17:25.884: E/AndroidRuntime(2678): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.arr_app/com.arr_app.MainActivity}: java.lang.NullPointerException 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.os.Handler.dispatchMessage(Handler.java:99) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.os.Looper.loop(Looper.java:137) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.app.ActivityThread.main(ActivityThread.java:5103) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at java.lang.reflect.Method.invokeNative(Native Method) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at java.lang.reflect.Method.invoke(Method.java:525) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at dalvik.system.NativeStart.main(Native Method) 
03-13 11:17:25.884: E/AndroidRuntime(2678): Caused by: java.lang.NullPointerException 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at  android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:146) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at com.arr_app.DBHelper.<init>(DBHelper.java:31) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at com.arr_app.MainActivity.<init>(MainActivity.java:44) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at java.lang.Class.newInstanceImpl(Native Method) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at java.lang.Class.newInstance(Class.java:1130) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.app.Instrumentation.newActivity(Instrumentation.java:1061) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128) 
03-13 11:17:25.884: E/AndroidRuntime(2678):  ... 11 more 

項目有Minimum Required SDK: API8Target SDK: API18

回答

0

給錯誤在onCreate()之前,在構造函數/成員變量初始化階段,您過早使用MainActivity作爲Context

DBHelper初始化爲onCreate()

+0

好吧,它的工作 – Galion