2014-06-18 2 views
0
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    switch(id){ 
    case R.id.switchActivity: 
    Intent intent = new Intent(this,SecondClass.class); 
    startActivity(intent); 
    } 

    return false; 
} 

사용자가 switchActivity 항목을 클릭하면 SecondClass 활동으로 전환되지만 switchActivity를 클릭하면 항상 충돌합니다.
로그 캣은 : 당신이 당신의 로그 캣 로그를 읽으려고하면작업 표시 줄을 사용하여 작업 시작 방법 항목

06-18 13:51:56.909: E/AndroidRuntime(1404): FATAL EXCEPTION: main 
06-18 13:51:56.909: E/AndroidRuntime(1404): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.intend/com.example.intend.SecondClass}: java.lang.NullPointerException: println needs a message 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.os.Handler.dispatchMessage(Handler.java:99) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.os.Looper.loop(Looper.java:137) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.app.ActivityThread.main(ActivityThread.java:5041) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at java.lang.reflect.Method.invokeNative(Native Method) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at java.lang.reflect.Method.invoke(Method.java:511) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at dalvik.system.NativeStart.main(Native Method) 
06-18 13:51:56.909: E/AndroidRuntime(1404): Caused by: java.lang.NullPointerException: println needs a message 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.util.Log.println_native(Native Method) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.util.Log.v(Log.java:117) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at com.example.intend.SecondClass.onCreate(SecondClass.java:28) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.app.Activity.performCreate(Activity.java:5104) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
06-18 13:51:56.909: E/AndroidRuntime(1404):  ... 11 more 
+2

로그 캣 로그 캣 로그 캣 로그 캣 로그 캣 로그 캣 – injecteer

+0

추가 로그 캣이 – user2477

+3

음을 돌보는 주셔서 감사합니다 ... 그것은 바로 로그 캣에서 문제를 말한다. 너는 그것을 읽으려고 했니? –

답변

1

문제는 당신이 그것을 할당하지 않고 referance에 사용하려고 시도하고 있다고 말했습니다 , 실제로 활동하지 않습니다. 그런 다음 NullPointerException을 던집니다. 그리고 여기에 라인을의

at com.example.intend.SecondClass.onCreate(SecondClass.java:28) 
+0

아, 맞아요, SecondClass에서 오래된 코드를 삭제하는 것을 잊었습니다 : D – user2477

관련 문제