在虚拟机打开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);
}
本文介绍了如何解决在虚拟机中打开Android应用时遇到的“Unfortunately,Activity_02has stopped”错误。通过分析LogCat日志,发现问题是由于未在AndroidManifest.xml中注册新的Activity类及未设置布局文件引起,并提供了具体的解决步骤。
1792

被折叠的 条评论
为什么被折叠?



