这是我的第一个 Android 程序。基本上我检查一个条件并切换到一个错误消息页面。我确信错误屏幕代码(ErrorScreen.java)是正确的。
public class ABC extends Activity {
...
private void init(){
if (i > 0)
{
startActivity(new Intent(this, ErrorScreen.class));
finish();
}
}
}
每次运行到'startActivity'时,程序都会崩溃。我错过了什么?日志显示:
12-13 17:05:07.205: D/AndroidRuntime(30890): Shutting down VM
12-13 17:05:07.205: W/dalvikvm(30890): threadid=1: thread exiting with uncaught exception (group=0x40c6d1f8)
12-13 17:05:07.215: E/AndroidRuntime(30890): FATAL EXCEPTION: main
12-13 17:05:07.215: E/AndroidRuntime(30890): java.lang.NullPointerException
12-13 17:05:07.215: E/AndroidRuntime(30890): at android.app.Activity.startActivityForResult(Activity.java:3252)
12-13 17:05:07.215: E/AndroidRuntime(30890): at android.app.Activity.startActivity(Activity.java:3359)
12-13 17:05:07.215: E/AndroidRuntime(30890): at com.stoyan.abc.ABC.init(ABC.java:373)
12-13 17:05:07.215: E/AndroidRuntime(30890): at com.stoyan.abc.ABC.analyze(ABC.java:83)