Android中为什么在内部类中调用外部类的TextView.setText()程序会崩溃,应该怎么解决
publicclassMainActivityextendsActionBarActivity{protectedvoidonCreate(BundlesavedInst...
public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
//初始化textView
textViewHour = (TextView) findViewById(R.id.tv_hour);
textViewMin = (TextView) findViewById(R.id.tv_min);
textViewSec = (TextView) findViewById(R.id.tv_sec);
其他内容省略
}
public class MyBroadcastReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
int hour = bundle.getInt("hour");
int min = bundle.getInt("min");
int sec = bundle.getInt("sec");
System.out.println(hour + " " + min + " " + sec);
textViewHour.setText(hour);
textViewMin.setText(min);
textViewSec.setText(sec);
}
}
错误的那行代码是 textViewHour.setText(hour); textViewHour是一个TextView,已经初始化了 展开
protected void onCreate(Bundle savedInstanceState) {
//初始化textView
textViewHour = (TextView) findViewById(R.id.tv_hour);
textViewMin = (TextView) findViewById(R.id.tv_min);
textViewSec = (TextView) findViewById(R.id.tv_sec);
其他内容省略
}
public class MyBroadcastReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
int hour = bundle.getInt("hour");
int min = bundle.getInt("min");
int sec = bundle.getInt("sec");
System.out.println(hour + " " + min + " " + sec);
textViewHour.setText(hour);
textViewMin.setText(min);
textViewSec.setText(sec);
}
}
错误的那行代码是 textViewHour.setText(hour); textViewHour是一个TextView,已经初始化了 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询