无法实例化活动组件信息 - java.lang.ClassNotFoundException

Posted

技术标签:

【中文标题】无法实例化活动组件信息 - java.lang.ClassNotFoundException【英文标题】:unable to instantiate activity componentinfo - java.lang.ClassNotFoundException 【发布时间】:2015-05-06 02:16:20 【问题描述】:

我已将活动添加到清单文件并尝试过。仍然得到同样的错误。我收到以下运行时错误(从 logcat 复制粘贴):

> 03-04 14:19:19.790: E/androidRuntime(864): FATAL EXCEPTION: main 03-04
> 14:19:19.790: E/AndroidRuntime(864): Process:
> com.example.eclipsevisacheckout, PID: 864 03-04 14:19:19.790:
> E/AndroidRuntime(864): 
> 
> java.lang.RuntimeException: Unable to instantiate activity
> ComponentInfocom.example.eclipsevisacheckout/com.example.eclipsevisacheckout.MainActivity:
> java.lang.ClassNotFoundException: Didn't find class
> "com.example.eclipsevisacheckout.MainActivity"  on path:
> DexPathList[[zip file
> "/data/app/com.example.eclipsevisacheckout-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.eclipsevisacheckout-1,
> /system/lib]]
> 
> 03-04 14:19:19.790: E/AndroidRuntime(864):    at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
> 03-04 14:19:19.790: E/AndroidRuntime(864):    at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
> 03-04 14:19:19.790: E/AndroidRuntime(864):    at
> android.app.ActivityThread.access$800(ActivityThread.java:135) 03-04
> 14:19:19.790: E/AndroidRuntime(864):  at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
> 03-04 14:19:19.790: E/AndroidRuntime(864):    at
> android.os.Handler.dispatchMessage(Handler.java:102) 03-04
> 14:19:19.790: E/AndroidRuntime(864):  at
> android.os.Looper.loop(Looper.java:136) 03-04 14:19:19.790:
> E/AndroidRuntime(864):    at
> android.app.ActivityThread.main(ActivityThread.java:5017) 03-04
> 14:19:19.790: E/AndroidRuntime(864):  at
> java.lang.reflect.Method.invokeNative(Native Method) 03-04
> 14:19:19.790: E/AndroidRuntime(864):  at
> java.lang.reflect.Method.invoke(Method.java:515) 03-04 14:19:19.790:
> E/AndroidRuntime(864):    at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
> 03-04 14:19:19.790: E/AndroidRuntime(864):    at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 03-04
> 14:19:19.790: E/AndroidRuntime(864):  at
> dalvik.system.NativeStart.main(Native Method) 03-04 14:19:19.790:
> E/AndroidRuntime(864): Caused by: java.lang.ClassNotFoundException:
> Didn't find class "com.example.eclipsevisacheckout.MainActivity" on
> path: DexPathList[[zip file
> "/data/app/com.example.eclipsevisacheckout-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.eclipsevisacheckout-1,
> /system/lib]] 03-04 14:19:19.790: E/AndroidRuntime(864):  at
> dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
> 03-04 14:19:19.790: E/AndroidRuntime(864):    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:497) 03-04
> 14:19:19.790: E/AndroidRuntime(864):  at
> java.lang.ClassLoader.loadClass(ClassLoader.java:457) 03-04
> 14:19:19.790: E/AndroidRuntime(864):  at
> android.app.Instrumentation.newActivity(Instrumentation.java:1061)
> 03-04 14:19:19.790: E/AndroidRuntime(864):    at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
> 03-04 14:19:19.790: E/AndroidRuntime(864):    ... 11 more

Android Manifest file:

> <?xml version="1.0" encoding="utf-8"?> <manifest
> xmlns:android="http://schemas.android.com/apk/res/android"
>     package="com.example.eclipsevisacheckout"
>     android:versionCode="1"
>     android:versionName="1.0" >
>     <uses-permission android:name="android.permission.INTERNET" />
>     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
>     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
>     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
>     <uses-permission android:name="android.permission.READ_CONTACTS" />
>     <uses-sdk
>         android:minSdkVersion="8"
>         android:targetSdkVersion="21" />
>     <application
>         android:allowBackup="true"
>         android:icon="@drawable/ic_launcher"
>         android:label="@string/app_name"
>         android:theme="@style/AppTheme" >
>         <activity
>             android:name="com.example.eclipsevisacheckout.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>
>         <activity
>             android:name="com.visa.checkout.VisaMcomActivity"
>             android:configChanges="layoutDirection"/>
>     </application> </manifest>

【问题讨论】:

请向我们展示您的清单文件,或者至少向我们展示您声明活动的部分,也许有问题。你是不是这样Starting an Activity ? 我在下面发布了我的清单文件。是的,我正在使用相同的方式开始一项活动。 【参考方案1】:

这通常意味着您忘记在清单中引用您的活动。

【讨论】:

【参考方案2】:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.eclipsevisacheckout"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.eclipsevisacheckout.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>

        <activity
               android:name="com.visa.checkout.VisaMcomActivity"
               android:configChanges="layoutDirection"/>
    </application>
</manifest>

【讨论】:

我不太确定,但请从 com.example.eclipsevisacheckout.MainActivity android:name=".MainActivity" 中删除 com.example.eclipsevisacheckout 并重试. 包或活动名称中没有拼写错误? 没有。当我控制 + 单击它时,按预期将我带到 Mainactivity 类。 看看这里***.com/questions/19523167/…。也许你能找到对你有帮助的东西。如果没有,请给我们留言。祝你好运。

以上是关于无法实例化活动组件信息 - java.lang.ClassNotFoundException的主要内容,如果未能解决你的问题,请参考以下文章

调用片段活动错误无法实例化活动。无法转换为 android.app.Activity

“无法实例化活动 ComponentInfo”代表啥?

“无法实例化活动”错误

无法实例化活动 ComponentInfo

java.lang.RuntimeException:无法实例化活动 ComponentInfo:java.lang.ClassNotFoundException

java - Android Studio - 无法实例化活动