雖然我正在調試代碼,它顯示沒有錯誤...但在運行應用程序時,它顯示「不幸的應用程序已停止」。這是我的活動2頁...從這同時單擊下一步按鈕應該移動到活動3個page.this頁是我的活動第2頁模擬器顯示「不幸的應用程序已停止」
package com.example.admin.androidapp;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class Activity2 extends Activity {
Button btn11;
Button btn22;
public Intent intent;
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2);
btn11 = (Button) findViewById(R.id.button2);
btn22 = (Button) findViewById(R.id.button5);
btn = (Button) findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button2:
intent = new Intent(Activity2.this, Activity3.class);
startActivity(intent);
break;
case R.id.button5:
intent= new Intent(Activity2.this, Welcome.class);
startActivity(intent);
break;
}
}
});
}
}
===============================================================
here is my Activity3 page:
package com.example.admin.androidapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class Activity3 extends Activity{
RadioGroup radiogroup;
Button btn1;
private Intent mIntent;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity3);
radiogroup = (RadioGroup) findViewById(R.id.radiogroup);
btn1 = (Button) findViewById(R.id.button);
radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int RadioID) {
RadioButton rd = (RadioButton) radioGroup.findViewById(RadioID);
switch (rd.getId()) {
case R.id.radioButton7:
mIntent = new Intent(Activity3.this, Terminate.class);
break;
case R.id.radioButton8:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton10:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton11:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton15:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton16:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton17:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton18:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton19:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton13:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton12:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
case R.id.radioButton14:
mIntent = new Intent(Activity3.this, Activity4.class);
break;
}
}
}
======================== ================== 請檢查上面的代碼,並幫助我在這個問題.. 在此先感謝。 和即時消息在logcat中,而單擊按鈕像java.lang.NullPointerException:試圖調用虛擬方法
可能重複[什麼是空指針異常,以及如何解決它?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how -do-i-fix-it) – Gosu
'btn'它在Activity2中的定義?請檢查.. –
發佈您的logcat。 –