嗨,我只想问为什么我无法启动我的程序,当我从 MessageBox 或 AlertBox 启动时它总是显示错误。我想要做的是,如果玩家在初学者阶段没有回答超过 15 个问题,他就不能进入学习者阶段,当他点击学习者时,它会显示一个消息框,他需要回答 10+能够进入下一轮的答案是我的代码
public class Menu extends Activity
{
private Integer beginnerAns = 0;
Button beginner, learner;
@Override
protected void onCreate(Bundle MenuButtons)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(MenuButtons);
setContentView(R.layout.menu);
beginner = (Button) findViewById(R.id.btnBeginner);
learner = (Button) findViewById(R.id.btnLearner);
beginner.setOnClickListener(myOnlyhandler);
learner.setOnClickListener(myOnlyhandler);
}
View.OnClickListener myOnlyhandler = new View.OnClickListener(){
public AlertDialog.Builder dlgAlert = new AlertDialog.Builder(Menu.this);
@Override
public void onClick(View v)
{
switch(v.getId()) {
case R.id.btnBeginner:
Intent openBeginner = new Intent("com.thesis.logipic.BEGINNER");
startActivity(openBeginner);
break;
case R.id.btnLearner:
if (beginnerAns < 15)
{
dlgAlert.setMessage("wrong password or username");
dlgAlert.setTitle("Error Message...");
dlgAlert.setPositiveButton("OK", null);
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
else
{
Intent openLearner = new Intent("com.thesis.logipic.GAMEPLAY");
startActivity(openLearner);
}
break;
}
}
};
}
和日志猫
10-06 21:00:28.673: D/AndroidRuntime(561): Shutting down VM
10-06 21:00:28.692: W/dalvikvm(561): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-06 21:00:28.712: E/AndroidRuntime(561): FATAL EXCEPTION: main
10-06 21:00:28.712: E/AndroidRuntime(561): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thesis.logipic/com.thesis.logipic.Menu}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.os.Looper.loop(Looper.java:123)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-06 21:00:28.712: E/AndroidRuntime(561): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 21:00:28.712: E/AndroidRuntime(561): at java.lang.reflect.Method.invoke(Method.java:521)
10-06 21:00:28.712: E/AndroidRuntime(561): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-06 21:00:28.712: E/AndroidRuntime(561): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-06 21:00:28.712: E/AndroidRuntime(561): at dalvik.system.NativeStart.main(Native Method)
10-06 21:00:28.712: E/AndroidRuntime(561): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.Activity.getSystemService(Activity.java:3526)
10-06 21:00:28.712: E/AndroidRuntime(561): at com.android.internal.app.AlertController$AlertParams.<init>(AlertController.java:743)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:273)
10-06 21:00:28.712: E/AndroidRuntime(561): at com.thesis.logipic.Menu$1.<init>(Menu.java:38)
10-06 21:00:28.712: E/AndroidRuntime(561): at com.thesis.logipic.Menu.<init>(Menu.java:37)
10-06 21:00:28.712: E/AndroidRuntime(561): at java.lang.Class.newInstanceImpl(Native Method)
10-06 21:00:28.712: E/AndroidRuntime(561): at java.lang.Class.newInstance(Class.java:1429)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-06 21:00:28.712: E/AndroidRuntime(561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
10-06 21:00:28.712: E/AndroidRuntime(561): ... 11 more