【问题标题】:How to call correctly few class (intents) using a button?如何使用按钮正确调用少数类(意图)?
【发布时间】:2011-01-21 09:07:34
【问题描述】:

我是 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);
  }}

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

【问题讨论】:

    标签: android class button android-intent oncreate


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2014-08-11
      • 2019-02-11
      • 2015-02-04
      • 2017-06-23
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      相关资源
      最近更新 更多