android - 错误在路径 : DexPathList[[zip file 上找不到类 "com.example.i.MainActivity"

标签 android

如何修复以下错误。

         FATAL EXCEPTION: main
         Process: com.example.i, PID: 10071
         java.lang.RuntimeException: Unable to instantiate activity 
    ComponentInfo{com.example.i/com.example.i.MainActivity}: java.lang.ClassNotFoundException: Didn't find class 
    "com.example.i.MainActivity" on path: DexPathList[[zip file "/data
/app/com.example.i-11.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.i-11, /vendor/lib, /system/lib]]
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)
            at android.app.ActivityThread.access$800(ActivityThread.java:163)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5335)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.i.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.i-11.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.i-11, /vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)

这是完整的主要 Activity

公共(public)类 MainActivity 扩展 AppCompatActivity {

        @Override
    public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            setContentView(R.layout.activity_main);
            initToolbars();
        }
        private void initToolbars() {

            Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbar_bottom);
            toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()){
                        case R.id.action_settings:
                            // TODO
                            break;
                        // TODO: Other cases
                    }
                    return true;
                }
            });
            toolbarBottom.inflateMenu(R.menu.main);

        }
        @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();


            return true;

            //return super.onOptionsItemSelected(item);
        }
}

这是xml

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_bottom"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:minHeight="?attr/actionBarSize" />

</RelativeLayout>

这是风格

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->

        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

libs 存在于此处 ...\workspace\i\libs 和工作场所中的 i/libs/..

最佳答案

错误:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.i.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.i-11.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.i-11, /vendor/lib, /system/lib]]

我也遇到过这个问题。

你的 MainActivity.java 被排除在编译之外,所以这个类不包含在 .apk

.idea/compiler.xml 文件的 excludeFromCompile 部分中删除以下行

<file url="file://$PROJECT_DIR$/src/com/example/i/MainActivity.java" />

关于android - 错误在路径 : DexPathList[[zip file 上找不到类 "com.example.i.MainActivity",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33006694/

相关文章:

Android 从纵向 Activity 过渡到横向 Activity 时没有动画

Android:方向改变时的后退按钮动画

java - Android xml 文件突然显示 java 代码。

当我转动屏幕或屏幕保护程序激活时,Android 广播应用程序停止播放

android - 当设备在我的用户目录中时,为什么 Android 模拟器会报告 "unknown virtual device"?

android - 如何让我的应用出现在 Google Now 的电话搜索列表中?

android - 结合拖放和缩放

android - Google Play 商店应用提交规则

java - 学习 Android Java - 应用程序失败

c# - Xamarin 文件 Mime 类型