在虚拟机打开app出现Unfortunately,Activity_02 has stopped。
LogCat 显示 android.content.ActivityNotFoundExceptiona:Unable to find explicit activity class 提醒找不到activity,由于每一个新增的Activity类型的子类都需要在AndroidManifest.xml中进行注册,这里没有注册OtherActivity.java导致出错,解决方法是在
AndroidManifest.xml中的第一个activity框架后加上如下代码。
<activity
android:name=".OtherActivity"
android:label="@string/other"/>
android:name=".OtherActivity"
android:label="@string/other"/>
LogCat 显示attempt to invoke virtual method'void android.widget.TextView' 经检查发现OtherActivity.java当中的OnCreate函数内没有设置布局文件(红色代码),设置布局文件后运行正常。
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.other); //设置布局文件
myTextView=(TextView)findViewById(R.id.myTextView);
myTextView.setText(R.string.other);
}
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.other); //设置布局文件
myTextView=(TextView)findViewById(R.id.myTextView);
myTextView.setText(R.string.other);
}