错误未在路径上找到类“com.example.i.MainActivity”:DexPathList [[zip文件

时间:2015-10-08 04:33:16

标签: 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)

这是完整的主要活动

公共类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 /..

1 个答案:

答案 0 :(得分:2)

错误:

  

引起:java.lang.ClassNotFoundException:没有找到类   路径上的“com.example.i.MainActivity”:DexPathList [[zip文件   “/data/app/com.example.i-11.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.i-11,   / vendor / lib,/ system / lib]]

我也遇到过这个问题。

您的MainActivity.java已从编译中排除,因此此类未包含在.apk

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

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