运行一个项目时,模拟器报下面的错:
The application ...has stoped unexpectedly,please try again.
logcat中的错误信息是java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.neu/com.neu.Business.MainActivity}: java.lang.ClassNotFoundException: com.neu.Business.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.neu-1.apk]
我的MainActivity代码如下:
public class MainActivity extends TabActivity{ private TabWidget mTabWidget; private TabHost mTabHost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTabHost = getTabHost(); //将要显示的Activity载入TabHost控件 setTabIndicator("已订购", 1, new Intent(this, Business_ordered_Activity.class)); setTabIndicator("WIFI",2,new Intent(this,Wifi_Activity.class)); setTabIndicator("未订购", 3, new Intent(this,UnOrdered_Activity.class)); setTabIndicator("其他", 4, new Intent(this,Other_Activity.class)); } private void setTabIndicator(String title,int nId,Intent intent){ //指定Tab样式 View view = LayoutInflater.from(this.mTabHost.getContext()) .inflate(R.layout.tab_style, null); TextView text = (TextView)findViewById(R.id.tab_label); String strId = String.valueOf(nId); text.setText(title); //创建一个新的Tab TabHost.TabSpec localTabSpec = mTabHost.newTabSpec(strId) .setIndicator(view).setContent(intent); mTabHost.addTab(localTabSpec); } }
java.lang.ClassNotFoundException:com.neu.Business.MainActivity
类没找到,预测类名写错了?
检查你的AndroidManifest.xml,里面有包名和Activity的android:name,看错误出现了重复: com.neu/ com.neu.Business.MainActivity
谢谢你,错误已经解决了版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。