我现在一直在找几个小时的答案,但我的计算器根本无法工作:(
如果你能帮助我,我感激不尽。我在下面发布了清单代码。如果您需要查看MainActivity.java或其他任何内容,请通知我:)
<?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>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat上显示的错误
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
答案 0 :(得分:1)
以下是您的关键行
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。您可以发布以获得进一步的帮助。无论代码是什么,都要确保在调用之前对其进行初始化(因此不为空)。