当前位置: 代码迷 >> Android >> java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.exa,该如何处理
  详细解决方案

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.exa,该如何处理

热度:431   发布时间:2016-04-28 03:02:44.0
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.exa
本帖最后由 szliszt 于 2014-12-25 01:22:28 编辑
最近做安卓项目,按照helloworld做了一个安卓例子,启动报错如下(折腾了很久,始终没有找到解决办法):

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.xibaoming4/com.example.xibaoming4.MainActivity}: java.lang.ClassNotFoundException: com.example.xibaoming4.MainActivity


测试模拟器参数:
Plateform:4.0
API Level:14
CPU/ABI:ARM(armeabi-v7a)

调试报错信息:
12-24 16:44:56.349: W/dalvikvm(735): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-24 16:44:56.369: E/AndroidRuntime(735): FATAL EXCEPTION: main
12-24 16:44:56.369: E/AndroidRuntime(735): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.xibaoming4/com.example.xibaoming4.MainActivity}: java.lang.ClassNotFoundException: com.example.xibaoming4.MainActivity
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.os.Looper.loop(Looper.java:137)
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.app.ActivityThread.main(ActivityThread.java:4340)
12-24 16:44:56.369: E/AndroidRuntime(735):  at java.lang.reflect.Method.invokeNative(Native Method)
12-24 16:44:56.369: E/AndroidRuntime(735):  at java.lang.reflect.Method.invoke(Method.java:511)
12-24 16:44:56.369: E/AndroidRuntime(735):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-24 16:44:56.369: E/AndroidRuntime(735):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-24 16:44:56.369: E/AndroidRuntime(735):  at dalvik.system.NativeStart.main(Native Method)
12-24 16:44:56.369: E/AndroidRuntime(735): Caused by: java.lang.ClassNotFoundException: com.example.xibaoming4.MainActivity
12-24 16:44:56.369: E/AndroidRuntime(735):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-24 16:44:56.369: E/AndroidRuntime(735):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-24 16:44:56.369: E/AndroidRuntime(735):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
12-24 16:44:56.369: E/AndroidRuntime(735):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
12-24 16:44:56.369: E/AndroidRuntime(735):  ... 11 more

系统环境:
  Android DDMS 23.0.4.1468518
  Android Development Tools 23.0.4.1468518
  Android Hierarchy Viewer 23.0.4.1468518
  Android Native Development Tools 23.0.4.1468518
  Android Traceview 23.0.4.1468518
  Eclipse IDE for Android Developers 23.0.2.1259578
  Tracer for OpenGL ES 23.0.4.1468518


各种办法都尝试了
1、项目属性,order and export下的android private libaraies勾选过了。
2、manifest.xml文件也检查过了。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.xibaoming4"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />
        <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Dialog">
     <activity android:name=".MainActivity" android:label="xibaoming4">
<intent-filter android:label="@string/hello">
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
    </application>  
</manifest>

3、项目也clean过了...

还有什么办法?请各位高手指教!



------解决思路----------------------
xml布局文件可能有错,貌似连代码都没进入?
------解决思路----------------------
com.example.xibaoming4.MainActivity没被找到,但是你manifest.xml里面有,所以,你看看项目中的MainActivity对应的包名和名称是否和manifest.xml里面的一致。
另外<intent-filter android:label="@string/hello">这里面的 android:label="@string/hello"去掉试试。
  相关解决方案