2013-12-18 62 views
0

我的第一個活動代碼如下ADT說unforunately應用程序已經用於啓動一個新的活動click事件後停止

public class MainActivity extends Activity { 

Button mainActLoginBtn, mainActCreateBtn; 
EditText mainActUserEdt, mainActPswEdt; 
TextView tv; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    mainActLoginBtn = (Button) findViewById(R.id.btn1); 
    mainActCreateBtn = (Button) findViewById(R.id.btn2); 
    mainActUserEdt = (EditText) findViewById(R.id.edt1); 
    mainActPswEdt = (EditText) findViewById(R.id.edt2); 
    tv = (TextView) findViewById(R.id.tview); 
    mainActLoginBtn.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      String userString = mainActUserEdt.getText().toString(); 
      String pswString = mainActPswEdt.getText().toString(); 
      if (userString.contentEquals("Dev") 
        && pswString.contentEquals("1234")) { 
       tv.setText("Welcome " + userString 
         + "Click Proceed to further process"); 
       Intent successAct = new Intent("com.example.a_m_s.INTRO"); 
       startActivityForResult(successAct, 0); 

      } 
     } 

    }); 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

成功顯示第一窗口,它是一個登錄窗口中輸入後,該應用程序不運行登錄憑證,並單擊登錄按鈕在Android模擬器中生成錯誤 如果需要更多的參考代碼,我不能弄清楚什麼是問題,請詢問它。

+3

發表您的日誌貓錯誤 –

+0

張貼堆棧跟蹤和'INTRO'類並檢查表明活動進入。 – Raghunandan

回答

0

試試這個..

Intent successAct = new Intent(MainActivity.this,INTRO.class); 
       startActivity(successAct); 

例子:

mainActLoginBtn.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      String userString = mainActUserEdt.getText().toString(); 
      String pswString = mainActPswEdt.getText().toString(); 
      if (userString.contentEquals("Dev") 
        && pswString.contentEquals("1234")) { 
       tv.setText("Welcome " + userString 
         + "Click Proceed to further process"); 
       Intent successAct = new Intent(MainActivity.this,INTRO.class); 
        startActivity(successAct); 

      } 
     } 

    }); 
+0

它不起作用..... –

+0

@ user3114217發佈您的清單以及您在「EditText」中輸入的內容 – Hariharan

0

除了寫作startActivityForResult(successAct, 0);你需要寫startActivity(successAct);

mainActLoginBtn.setOnClickListener(new View.OnClickListener() { 

    @Override 
    public void onClick(View arg0) { 
     String userString = mainActUserEdt.getText().toString(); 
     String pswString = mainActPswEdt.getText().toString(); 
     if (userString.contentEquals("Dev") 
       && pswString.contentEquals("1234")) { 
      tv.setText("Welcome " + userString 
        + "Click Proceed to further process"); 
      Intent successAct = new Intent("com.example.a_m_s.INTRO"); 
       startActivity(successAct); 

     } 
    } 

}); 
相關問題