
android中程序没有错误显示android runtime
packagecom.example.mycheckbox;importandroid.os.Bundle;importandroid.app.Activity;impo...
package com.example.mycheckbox;
import android.os.Bundle;
import android.app.Activity;
import android.widget.*;
public class MyCheckBox extends Activity {
private TextView mTextView1;
private CheckBox mCheckBox1;
private CheckBox mCheckBox2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_check_box);
mTextView1=(TextView)findViewById(R.id.myTextView01);
mCheckBox1=(CheckBox)findViewById(R.id.myCheckBox01);
mCheckBox1=(CheckBox)findViewById(R.id.myCheckBox02);
mTextView1.setText("你所选择的服务有:");
mCheckBox1.setOnCheckedChangeListener(mCheckBoxChanged);
mCheckBox2.setOnCheckedChangeListener(mCheckBoxChanged);
}
private CheckBox.OnCheckedChangeListener mCheckBoxChanged
=new CheckBox.OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
String str0="所选的项目为:";
String str1=getString(R.string.str_checkbox01);
String str2=getString(R.string.str_checkbox02);
String strEmpty="没有选择任何服务";
if(mCheckBox1.isChecked()==true & mCheckBox2.isChecked()==true){
mTextView1.setText(str0+str1+"和"+str2);
}
else if(mCheckBox1.isChecked()==false & mCheckBox2.isChecked()==true){
mTextView1.setText(str0+str2);
}
else if(mCheckBox1.isChecked()==true & mCheckBox2.isChecked()==false){
mTextView1.setText(str0+str1);
}
else if(mCheckBox1.isChecked()==false & mCheckBox2.isChecked()==false){
mTextView1.setText(strEmpty);
}
}
};
} 展开
import android.os.Bundle;
import android.app.Activity;
import android.widget.*;
public class MyCheckBox extends Activity {
private TextView mTextView1;
private CheckBox mCheckBox1;
private CheckBox mCheckBox2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_check_box);
mTextView1=(TextView)findViewById(R.id.myTextView01);
mCheckBox1=(CheckBox)findViewById(R.id.myCheckBox01);
mCheckBox1=(CheckBox)findViewById(R.id.myCheckBox02);
mTextView1.setText("你所选择的服务有:");
mCheckBox1.setOnCheckedChangeListener(mCheckBoxChanged);
mCheckBox2.setOnCheckedChangeListener(mCheckBoxChanged);
}
private CheckBox.OnCheckedChangeListener mCheckBoxChanged
=new CheckBox.OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
String str0="所选的项目为:";
String str1=getString(R.string.str_checkbox01);
String str2=getString(R.string.str_checkbox02);
String strEmpty="没有选择任何服务";
if(mCheckBox1.isChecked()==true & mCheckBox2.isChecked()==true){
mTextView1.setText(str0+str1+"和"+str2);
}
else if(mCheckBox1.isChecked()==false & mCheckBox2.isChecked()==true){
mTextView1.setText(str0+str2);
}
else if(mCheckBox1.isChecked()==true & mCheckBox2.isChecked()==false){
mTextView1.setText(str0+str1);
}
else if(mCheckBox1.isChecked()==false & mCheckBox2.isChecked()==false){
mTextView1.setText(strEmpty);
}
}
};
} 展开
3个回答
展开全部
mTextView1=(TextView)findViewById(R.id.myTextView01);
mCheckBox1=(CheckBox)findViewById(R.id.myCheckBox01);
mCheckBox1=(CheckBox)findViewById(R.id.myCheckBox02);
仔细看一下初始化的语句
两条都是初始化的mCheckBox1的
mCheckBox1=(CheckBox)findViewById(R.id.myCheckBox01);
mCheckBox1=(CheckBox)findViewById(R.id.myCheckBox02);
仔细看一下初始化的语句
两条都是初始化的mCheckBox1的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错误应该是你的mCheckBox2为空吧,没有初始化mCheckBox2,初始化了两次mCheckBox1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询