找不到具有findViewById()的视图我找不到TextView打电话findViewById()即使ID确实存在。OtherActivity:public class OtherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
TextView textView = (TextView)findViewById(R.ID.txt02);
super.onCreate(savedInstanceState);//line 5
setContentView(R.layout.other_activity);
//textView.setText(ACCESSIBILITY_SERVICE);
Button button = (Button)findViewById(R.ID.otherActivity_Btn);
button.setText(R.string.otherActivityBtn);
button.setOnClickListener(new GoBackBtnListener(this));
}
class GoBackBtnListener implements OnClickListener {
OtherActivity other = null;
public GoBackBtnListener(OtherActivity p_other) {
other = p_other;
}
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(other, Activity01Activity.class);
other.startActivity(intent);
}
}}我在第5行添加了一个断点,并以调试模式启动了该项目。当它在断点停止时,我将鼠标移动到变量。textView它是空的。这个other_activity布局:<?xml version="1.0" encoding="utf-8"?><LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"><TextView
android:id="@+ID/txt02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/><Button
android:id="@+ID/otherActivity_Btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/></LinearLayout>我不认为TextView不应该被找到,但是为什么变量是textView零?
添加回答
举报
0/150
提交
取消