2011-06-03 86 views
1

我在清單活動:啓動活動導致了java.lang.RuntimeException

<activity android:name="RingdroidSelectActivity" 
      android:label="@string/main_activity_label"> 

    <intent-filter> 
     <action android:name="android.intent.action.GET_CONTENT" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.OPENABLE" /> 
     <data android:mimeType="audio/*" /> 
    </intent-filter> 

</activity> 

當使用如下代碼打開它:

startActivity (new Intent(getApplicationContext(), com.ringdroid.RingdroidSelectActivity.class)); 

我得到:

06-03 09:49:32.744: ERROR/AndroidRuntime(11360): FATAL EXCEPTION: main 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ringdroid/com.ringdroid.RingdroidSelectActivity}: java.lang.NullPointerException 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.os.Handler.dispatchMessage(Handler.java:99) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.os.Looper.loop(Looper.java:130) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.app.ActivityThread.main(ActivityThread.java:3683) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at java.lang.reflect.Method.invokeNative(Native Method) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at java.lang.reflect.Method.invoke(Method.java:507) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at dalvik.system.NativeStart.main(Native Method) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360): Caused by: java.lang.NullPointerException 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at com.ringdroid.RingdroidSelectActivity.onCreate(RingdroidSelectActivity.java:108) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
06-03 09:49:32.744: ERROR/AndroidRuntime(11360):  ... 11 more 

有什麼想法?

+0

問題似乎出現在您的活動代碼中,而不是啓動本身。由com.ringdroid.RingdroidSelectActivity.onCreate(RingdroidSelectActivity.java:108)引發java.lang.NullPointerException。發佈'RingdroidSelectActivity.java' – dmon 2011-06-03 13:59:42

+0

什麼是RingdroidSelectActivity.java:108? – Egor 2011-06-03 14:00:19

+0

它的代碼會導致錯誤: Intent intent = getIntent(); mWasGetContentIntent = intent.getAction()。equals( Intent.ACTION_GET_CONTENT); – OkyDokyman 2011-06-03 14:03:44

回答

0

顯然你有intent.getAction()== null。

修復您的代碼行:

mWasGetContentIntent = Intent.ACTION_GET_CONTENT.equals(intent.getAction()); 
+0

如果您指定要啓動的活動的類,則不必指定操作 – fleetway76 2011-06-03 14:17:54

0

對此代碼:

Intent intent = getIntent(); 
mWasGetContentIntent = intent.getAction().equals(Intent.ACTION_GET_CONTENT); 

這是最好的做法(常識)使用.equals()時把你知道不在左側爲空,所以你避免這些NullPointerException s。因此,將其重寫爲:

mWasGetContentIntent = Intent.ACTION_GET_CONTENT.equals(intent.getAction()); 
相關問題