不幸的是,我的应用程序已在Android设备上停止

时间:2019-04-20 18:37:10

标签: android

我是android的初学者,因此我遇到了这个问题。 在设备上运行我的应用程序时出现"Unfortunately MyApp has stopped"错误。 任何帮助都非常感谢。

这是堆栈跟踪

04-20 20:59:58.451 1747-1747/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ax2, PID: 1747
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.ax2/com.example.ax2.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2290)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
    at android.app.ActivityThread.access$800(ActivityThread.java:156)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:211)
    at android.app.ActivityThread.main(ActivityThread.java:5371)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
    at android.support.v7.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:249)
    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
    at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
    at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:191)
    at com.example.ax2.MainActivity.<init>(MainActivity.java:19)
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at java.lang.Class.newInstance(Class.java:1606)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442) 
    at android.app.ActivityThread.access$800(ActivityThread.java:156) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:211) 
    at android.app.ActivityThread.main(ActivityThread.java:5371) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740) 

0 个答案:

没有答案