无法实例化活动componentinfo - java.lang.ClassNotFoundException

时间:2015-03-04 21:38:57

标签: android android-intent android-emulator

我已将活动添加到清单文件并尝试过。仍然得到同样的错误。我得到以下运行时错误(从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
> ComponentInfo{com.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>

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

<?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>