0

我是 Java Android 开发的初学者。我正在使用 Eclipse SDK 3.6.1 版本。我正在尝试调用新意图,但我的应用程序总是意外停止。我是否正确地调用了新意图?

一级:

public class first extends Activity {


  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button SignIn = (Button) findViewById(R.id.SignIn);
    SignIn.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
          EditText pw = (EditText) findViewById(R.id.editPasswd);
            if(pw.getText().toString().equals("123")) {                     

                 Intent intent = new Intent(first.this, second.class);
                 startActivity(intent);                                  
             }
            else {
                  Toast.makeText(getBaseContext(), "Wrong PIN" ,
                  Toast.LENGTH_LONG).show();
            }   

      }});
  }
 }

二等:

public class second extends Activity {

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.loginas);   

    Button Button01 = (Button) findViewById(R.id.Button01);
    Button01.setOnClickListener(new OnClickListener() { 

    public void onClick(View v) {
      if(v.getId() == R.id.Button01) { 

          Intent intent = new Intent(second.this, third.class);
          startActivity(intent); 
     }} 
    });
  }
}

第三类:

public class third extends Activity {

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lock);
  }}

当我输入正确的密码时,应用程序显示消息“应用程序()已意外停止。请重试”。首先我想知道我的代码是正确的。

4

1 回答 1

1

无论您要显示什么活动,都必须在文件中提及这些活动。AndroidManifest.xml例如,在您的应用程序中,AndroidManifest.xml文件中提到的第一个、第二个、第三个活动

于 2011-01-21T09:59:43.203 回答