package com.ebonybutler.cexample3;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Main.this, Second.class));
}
});
}
}
每次我嘗試運行它在打開時崩潰,錯誤我的應用程序保持模擬器或Android手機
「對不起!應用程序示例3(processcom.ebonybutler.cexample3) 已意外停止。請再試一次。'
我不知道是什麼讓它在啓動時崩潰,因爲所有的java文件看起來都不錯,或者至少沒有任何錯誤。請幫忙!我已經在下面的logcat中添加了信息,但是我正在嘗試解釋它對我說的話。
11-02 09:29:10.261: E/AndroidRuntime(276): FATAL EXCEPTION: main
11-02 09:29:10.261: E/AndroidRuntime(276): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebonybutler.cexample3/com.ebonybutler.cexample3.Main}: java.lang.NullPointerException
11-02 09:29:10.261: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-02 09:29:10.261: E/AndroidRuntime(276): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-02 09:29:10.261: E/AndroidRuntime(276): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-02 09:29:10.261: E/AndroidRuntime(276): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-02 09:29:10.261: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:99)
11-02 09:29:10.261: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123)
11-02 09:29:10.261: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-02 09:29:10.261: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 09:29:10.261: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521)
11-02 09:29:10.261: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-02 09:29:10.261: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-02 09:29:10.261: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)
11-02 09:29:10.261: E/AndroidRuntime(276): Caused by: java.lang.NullPointerException
11-02 09:29:10.261: E/AndroidRuntime(276): at com.ebonybutler.cexample3.Main.onCreate(Main.java:21)
11-02 09:29:10.261: E/AndroidRuntime(276): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-02 09:29:10.261: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-02 09:29:10.261: E/AndroidRuntime(276): ... 11 more
通常在那裏我得到了自動覆蓋。這是不對的?它應該是什麼呢?我從來沒有在這之前或在我的任何其他Java文件的問題。感謝您的幫助mjmarsh。 – user1026229
看到我的編輯對我的想法是錯誤的解釋 –
感謝您的幫助mjmarsh!這似乎有幫助!它在仿真器和電話上再次運行。 – user1026229