Eclipse,Android无法看到活动 - 无法实例化活动ComponentInfo错误

时间:2015-09-27 21:03:50

标签: java android eclipse

我经常在Android Studio上工作,所以我对Eclipse项目的构成并不熟悉。一般来说,我已经设置了我的项目,我收到了错误日志,如下所示。乍一看似乎非常微不足道,因为你会认为“清单中没有任何活动,或者你以错误的方式指明了”。但我已经花了3个小时与之斗争,我不知道哪里可能是错误。

一般情况下,我试图从

重命名活动
kamil.krzyk.agh.eds.activity.MenuActivity

例如:

.activity.MenuActivity

或只是:

.MenuActivity

多次清理项目,重建,重新启动IDE,将活动类移动到root,检查是否在项目属性中 - >生成器一切都经过检查Java Build Path的状态是: enter image description here

我的清单代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="kamil.krzyk.agh.eds"
    android:versionCode="301"
    android:versionName="3.01" >

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true" />

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

    <uses-permission android:name="android.permission.CAMERA" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.front"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.front.autofocus"
        android:required="false" />

    <application
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <activity
            android:name="kamil.krzyk.agh.eds.activity.MenuActivity"
            android:configChanges="keyboardHidden|orientation"
            android:icon="@drawable/icon"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

我的项目树看起来像这样: enter image description here

我的硬盘上的MenuActivity.class的位置是: enter image description here

一般来说,项目编译/构建,我可以运行它,但我立即得到错误。我曾经改变过一次项目包。我看不出哪里是错误的。请看看它,给出一些建议,想法,无论如何你都可以帮助我。谢谢。

错误日志:

09-27 22:52:27.120: E/AndroidRuntime(32308): FATAL EXCEPTION: main
    09-27 22:52:27.120: E/AndroidRuntime(32308): Process: kamil.krzyk.agh.eds, PID: 32308
    09-27 22:52:27.120: E/AndroidRuntime(32308): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{kamil.krzyk.agh.eds/kamil.krzyk.agh.eds.activity.MenuActivity}: java.lang.ClassNotFoundException: Didn't find class "kamil.krzyk.agh.eds.activity.MenuActivity" on path: DexPathList[[zip file "/data/app/kamil.krzyk.agh.eds-1/base.apk"],nativeLibraryDirectories=[/data/app/kamil.krzyk.agh.eds-1/lib/arm, /vendor/lib, /system/lib]]
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.os.Handler.dispatchMessage(Handler.java:102)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.os.Looper.loop(Looper.java:135)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.app.ActivityThread.main(ActivityThread.java:5254)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at java.lang.reflect.Method.invoke(Native Method)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at java.lang.reflect.Method.invoke(Method.java:372)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    09-27 22:52:27.120: E/AndroidRuntime(32308): Caused by: java.lang.ClassNotFoundException: Didn't find class "kamil.krzyk.agh.eds.activity.MenuActivity" on path: DexPathList[[zip file "/data/app/kamil.krzyk.agh.eds-1/base.apk"],nativeLibraryDirectories=[/data/app/kamil.krzyk.agh.eds-1/lib/arm, /vendor/lib, /system/lib]]
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
    09-27 22:52:27.120: E/AndroidRuntime(32308):    ... 10 more
    09-27 22:52:27.120: E/AndroidRuntime(32308):    Suppressed: java.lang.ClassNotFoundException: kamil.krzyk.agh.eds.activity.MenuActivity
    09-27 22:52:27.120: E/AndroidRuntime(32308):        at java.lang.Class.classForName(Native Method)
    09-27 22:52:27.120: E/AndroidRuntime(32308):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    09-27 22:52:27.120: E/AndroidRuntime(32308):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    09-27 22:52:27.120: E/AndroidRuntime(32308):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    09-27 22:52:27.120: E/AndroidRuntime(32308):        ... 13 more
    09-27 22:52:27.120: E/AndroidRuntime(32308):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

1 个答案:

答案 0 :(得分:0)

从你的截图我想包kamil.krzyk.agh.eds(有白色)不是源文件夹。那么看看你的项目设置。

根据这个answer你应该:

  

右键单击项目并转到项目属性,然后转到java构建路径,然后在源选项卡中,单击添加文件夹按钮并添加`kamil.krzyk.agh.eds&#39; (或者你应该添加&#39; src&#39;文件夹)文件夹。