2014-11-01 128 views
0

還有一些關於此問題的其他問題,但它們都不適用於我的情況。我希望我能提供必要的信息。該活動沒有得到的onCreate方法,但在startActivity死亡()無法啓動活動NullPointerException

public void showPlaylist(View view){ 
     Intent i = new Intent(this,Playlist.class); 
     startActivity(i); 
    } 

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.www.Swipernoswiping" > 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.www.Swipernoswiping" 
      android:configChanges="orientation|keyboardHidden|screenSize" 
      android:label="@string/app_name" 
      android:theme="@style/FullscreenTheme"(Tried removing this line but it didn't help) > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

     <activity 
      android:name=".Playlist" 
      android:label="@string/app_name" 
      android:theme="@style/FullscreenTheme" /> 
    </application> 

</manifest> 

的logcat:

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2172) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296) 
     at android.app.ActivityThread.access$700(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281) 
     at android.os.Handler.dispatchMessage(Handler.java:99) 
     at android.os.Looper.loop(Looper.java:137) 
     at android.app.ActivityThread.main(ActivityThread.java:5293) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:511) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
     at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NullPointerException 
     at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109) 
     at com.overmindserver.www.swipernoswiping.Playlist.<init>(Playlist.java:30) 
     at java.lang.Class.newInstanceImpl(Native Method) 
     at java.lang.Class.newInstance(Class.java:1319) 
     at android.app.Instrumentation.newActivity(Instrumentation.java:1071) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296) 
            at android.app.ActivityThread.access$700(ActivityThread.java:151) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281) 
            at android.os.Handler.dispatchMessage(Handler.java:99) 
            at android.os.Looper.loop(Looper.java:137) 
            at android.app.ActivityThread.main(ActivityThread.java:5293) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:511) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
            at dalvik.system.NativeStart.main(Native Method) 

回答

0

錯誤com.overmindserver.www.hivemind.Playlist.<init>(Playlist.java:30)。您在onCreate()之前過早撥打getApplicationContext()

+0

這就是它!非常感謝你! – spintron 2014-11-01 14:24:52

0

可能是你可以給主要活動代碼

嘗試給的,而不是活動名稱,有時坐在原因問題

Intent i = new Intent(MainActivity.this,Playlist.class); 
startActivity(i); 
相關問題