关于java:不幸的是我的应用已停止在Android模拟器中

Unfortunately my app has stopped in Android Emulator

本问题已经有最佳答案,请猛点这里访问。

我已经找了几个小时的答案了,但我的计算器根本不工作:(

如果你能帮助我,我很感激。我已经发布了下面的清单代码。如果需要查看mainactivity.java或其他内容,请通知我:)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.elof_calc_2000_dragonslayerxx"
android:versionCode="1"
android:versionName="1.0">

 <uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="17" />

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
     android:name="com.example.elof_calc_2000_dragonslayerxx.MainActivity"
        android:label="@string/app_name">
        <intent-filter>
           

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
 </application>

</manifest>

Logcat上的错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
03-16 18:09:59.890: E/AndroidRuntime(895): FATAL EXCEPTION: main
03-16 18:09:59.890: E/AndroidRuntime(895): Process: com.example.elof_calc_2000_dragonslayerxx,     PID: 895
03-16 18:09:59.890: E/AndroidRuntime(895): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.elof_calc_2000_dragonslayerxx/com.example.elof_calc_2000_dragonslayerxx.MainActivity}: java.lang.NullPointerException
03-16 18:09:59.890: E/AndroidRuntime(895):  at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.os.Handler.dispatchMessage(Handler.java:102)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.os.Looper.loop(Looper.java:136)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.app.ActivityThread.main(ActivityThread.java:5017)
03-16 18:09:59.890: E/AndroidRuntime(895):  at java.lang.reflect.Method.invokeNative(Native Method)
03-16 18:09:59.890: E/AndroidRuntime(895):  at java.lang.reflect.Method.invoke(Method.java:515)
03-16 18:09:59.890: E/AndroidRuntime(895):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-16 18:09:59.890: E/AndroidRuntime(895):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-16 18:09:59.890: E/AndroidRuntime(895):  at dalvik.system.NativeStart.main(Native Method)
03-16 18:09:59.890: E/AndroidRuntime(895): Caused by: java.lang.NullPointerException
03-16 18:09:59.890: E/AndroidRuntime(895):  at com.example.elof_calc_2000_dragonslayerxx.MainActivity.onClickListeners(MainActivity.java:49)
03-16 18:09:59.890: E/AndroidRuntime(895):  at com.example.elof_calc_2000_dragonslayerxx.MainActivity.onCreate(MainActivity.java:22)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.app.Activity.performCreate(Activity.java:5231)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-16 18:09:59.890: E/AndroidRuntime(895):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-16 18:09:59.890: E/AndroidRuntime(895):  ... 11 more
03-16 18:16:23.316: E/AndroidRuntime(1100): FATAL EXCEPTION: main
03-16 18:16:23.316: E/AndroidRuntime(1100): Process: com.example.elof_calc_2000_dragonslayerxx, PID: 1100
03-16 18:16:23.316: E/AndroidRuntime(1100): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.elof_calc_2000_dragonslayerxx/com.example.elof_calc_2000_dragonslayerxx.MainActivity}: java.lang.NullPointerException
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.os.Looper.loop(Looper.java:136)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at java.lang.reflect.Method.invokeNative(Native Method)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at java.lang.reflect.Method.invoke(Method.java:515)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at dalvik.system.NativeStart.main(Native Method)
03-16 18:16:23.316: E/AndroidRuntime(1100): Caused by: java.lang.NullPointerException
03-16 18:16:23.316: E/AndroidRuntime(1100):     at com.example.elof_calc_2000_dragonslayerxx.MainActivity.onClickListeners(MainActivity.java:49)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at com.example.elof_calc_2000_dragonslayerxx.MainActivity.onCreate(MainActivity.java:22)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.app.Activity.performCreate(Activity.java:5231)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-16 18:16:23.316: E/AndroidRuntime(1100):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-16 18:16:23.316: E/AndroidRuntime(1100):     ... 11 more


这是你的要点

1
2
03-16 18:16:23.316: E/AndroidRuntime(1100): Caused by: java.lang.NullPointerException
03-16 18:16:23.316: E/AndroidRuntime(1100):     at com.example.elof_calc_2000_dragonslayerxx.MainActivity.onClickListeners(MainActivity.java:49)

在MainActivity的第49行上有一个NullPointerException。你可以张贴以获得进一步的帮助。无论存在什么代码,在调用它之前都要确保它已初始化(因此不是空的)。