因此,每当我单击启动页面上的按钮时,都会出现强制关闭错误。这是 main.xml 布局文件的类:
public class ForeverAloneActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnstrt = (Button) findViewById(R.id.toq1);
btnstrt.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
Intent frstq = new Intent(v.getContext(), QuestionOne.class);
startActivityForResult(frstq, 0);
这就是我认为产生错误的原因。此类与在启动页面上按下按钮时,您将被带到的页面相关:
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView (R.layout.frstq);
Button startQ2 = (Button) findViewById(R.id.toq2);
startQ2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
Intent toQ2 = new Intent(v.getContext(), QuestionTwo.class);
final EditText number = (EditText) findViewById(R.id.editText1);
final Toast error = Toast.makeText(QuestionOne.this, "Please insert a value", Toast.LENGTH_SHORT);
if (number.getText().toString().equals("")) {error.show();
}else{
startActivityForResult(toQ2, 0);}
if 语句与下一页一样,有一个 EditText 框。我试图这样做,如果 EditText 框中没有任何内容,它会显示一条 toast 消息,说“请插入一个值”。在将整数放入 EditText 框之前,该按钮将不起作用。
如果有人可以提供帮助,将不胜感激。
日志猫:
04-07 19:33:58.199: W/dalvikvm(362): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-07 19:33:58.221: E/AndroidRuntime(362): FATAL EXCEPTION: main
04-07 19:33:58.221: E/AndroidRuntime(362): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.kenning.foreveralone/com.kenning.foreveralone.QuestionOne}; have you declared this activity in your AndroidManifest.xml?
04-07 19:33:58.221: E/AndroidRuntime(362): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.app.Activity.startActivityForResult(Activity.java:2817)
04-07 19:33:58.221: E/AndroidRuntime(362): at com.kenning.foreveralone.ForeverAloneActivity$1.onClick(ForeverAloneActivity.java:22)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.view.View.performClick(View.java:2408)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.view.View$PerformClick.run(View.java:8816)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.os.Handler.handleCallback(Handler.java:587)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.os.Handler.dispatchMessage(Handler.java:92)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.os.Looper.loop(Looper.java:123)
04-07 19:33:58.221: E/AndroidRuntime(362): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-07 19:33:58.221: E/AndroidRuntime(362): at java.lang.reflect.Method.invokeNative(Native Method)
04-07 19:33:58.221: E/AndroidRuntime(362): at java.lang.reflect.Method.invoke(Method.java:521)
04-07 19:33:58.221: E/AndroidRuntime(362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-07 19:33:58.221: E/AndroidRuntime(362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-07 19:33:58.221: E/AndroidRuntime(362): at dalvik.system.NativeStart.main(Native Method)