Caused by: java.lang.ClassNotFoundException: cn.eoe.usingbc.MainActivity如何解决

xfsyj2014 2016-05-11 11:16:05
请问下面的报错该怎么解决呀,从晚上开始,所有新建项目都无法运行,都是这个报错 困扰好久了!!!非常谢谢




下面是代码
package com.example.service;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {
private Button btnStartService,btnStopService;
private Intent serviceIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStartService=(Button) findViewById(R.id.btnStartService);
btnStopService=(Button) findViewById(R.id.btnStopService);
btnStartService.setOnClickListener(this);
btnStopService.setOnClickListener(this);
serviceIntent=new Intent(this,EchoService.class);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btnStartService:

startService(serviceIntent);
break;

case R.id.btnStopService:
stopService(serviceIntent);
break;
}

}
}




package com.example.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class EchoService extends Service {

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
System.out.println("onCreate");
super.onCreate();
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
System.out.println("onDestroy");
super.onDestroy();
}

}



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.service.MainActivity" >

<Button
android:id="@+id/btnStartService"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StartService" />

<Button
android:id="@+id/btnStopService"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StopService" />

</LinearLayout>




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.service"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" android:allowTaskReparenting="false" android:hasCode="false">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="EchoService"></service>
</application>

</manifest>

...全文
185 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒲锦_up 2016-05-12
  • 打赏
  • 举报
回复
贴错代码了 cn.eoeo的项目报错 你贴个com.example 的代码干嘛
lx912356858 2016-05-12
  • 打赏
  • 举报
回复
两个包下的两个MainActivity,能找得到才怪... 你再好好看看 你想要的是哪个吧
淡淡的蛋蛋 2016-05-12
  • 打赏
  • 举报
回复
大兄弟,你报错误的类和你贴的图的类根本不是同一个啊
节操在此 2016-05-12
  • 打赏
  • 举报
回复
你没发现你启动的MainActivity包名都跟你的项目包名不一样么,clean一下项目,如果还是报错,MainActivity注册的时候用完整包名

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧