0

我的 android 应用程序在加载 main.xml 之前崩溃。这是抛出的异常

java.lang.RuntimeException:无法恢复活动...:java.lang.NullPointerException

发生什么了?

为了完整起见,我附上了我的 manifest.xml

 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="saverio.puccia.nfcauth"
        android:versionCode="1"
        android:versionName="1.0" >

    //permission

        <uses-sdk android:minSdkVersion="10" />
        <uses-permission android:name="android.permission.NFC"></uses-permission>
        <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

    //main declaration

        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <activity
                android:name=".NFCAuthActivity"
                android:label="@string/app_name" >

                //intent filter declaration

                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
                <intent-filter>
                    <action android:name="android.intent.action.NDEF_DISCOVER" />

                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>


            </activity>
        </application>

    </manifest>

LOGCAT

06-25 11:03:23.670: E/AndroidRuntime(4323): FATAL EXCEPTION: main

06-25 11:03:23.670: E/AndroidRuntime(4323): java.lang.RuntimeException: Unable to resume activity {saverio.puccia.nfcauth/saverio.puccia.nfcauth.NFCAuthActivity}: java.lang.NullPointerException

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2456)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2484)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1998)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.ActivityThread.access$600(ActivityThread.java:127)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.os.Handler.dispatchMessage(Handler.java:99)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.os.Looper.loop(Looper.java:137)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.ActivityThread.main(ActivityThread.java:4507)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at java.lang.reflect.Method.invokeNative(Native Method)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at java.lang.reflect.Method.invoke(Method.java:511)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at dalvik.system.NativeStart.main(Native Method)

06-25 11:03:23.670: E/AndroidRuntime(4323): Caused by: java.lang.NullPointerException

06-25 11:03:23.670: E/AndroidRuntime(4323):     at saverio.puccia.nfcauth.NFCAuthActivity.onResume(NFCAuthActivity.java:103)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1157)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.Activity.performResume(Activity.java:4539)

06-25 11:03:23.670: E/AndroidRuntime(4323):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2446)

06-25 11:03:23.670: E/AndroidRuntime(4323):     ... 12 more

06-25 11:03:23.670: W/ActivityManager(1998):   Force finishing activity r.intent.getComponent().flattenToShortString()
4

1 回答 1

0

从 logcat 中的这一行可以看出:

06-25 11:03:23.670: E/AndroidRuntime(4323): 在 saverio.puccia.nfcauth.NFCAuthActivity.onResume(NFCAuthActivity.java:103)

NullPointerException你在第 103 行有一个onResume函数。去那里,这将是你的答案。

于 2012-06-25T09:11:56.970 回答