繁体   English   中英

不幸的是,Android应用程序启动错误已停止

[英]Android application launch error with Unfortunately has stopped

我在Mac上的Eclipse中创建了一个新的Android应用程序项目。 我将其设置为Android 4.4.2 SDK。

当我在物理Nexus 7平板电脑中安装此示例项目时,它会引发以下启动错误。 我尚未在此项目中添加任何内容,它只是按原样创建的示例项目。

不幸已经停止了

04-13 00:16:05.395: W/dalvikvm(6761): Unable to resolve superclass of Lcom/example/myfinaltest/MainActivity; (2)
04-13 00:16:05.395: W/dalvikvm(6761): Link of class 'Lcom/example/myfinaltest/MainActivity;' failed
04-13 00:16:05.395: D/AndroidRuntime(6761): Shutting down VM
04-13 00:16:05.395: W/dalvikvm(6761): threadid=1: thread exiting with uncaught exception (group=0x415bcba8)
04-13 00:16:05.395: E/AndroidRuntime(6761): FATAL EXCEPTION: main
04-13 00:16:05.395: E/AndroidRuntime(6761): Process: com.example.myfinaltest, PID: 6761
04-13 00:16:05.395: E/AndroidRuntime(6761): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myfinaltest/com.example.myfinaltest.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myfinaltest.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfinaltest-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfinaltest-2, /vendor/lib, /system/lib]]
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.os.Looper.loop(Looper.java:136)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at java.lang.reflect.Method.invokeNative(Native Method)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at java.lang.reflect.Method.invoke(Method.java:515)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at dalvik.system.NativeStart.main(Native Method)
04-13 00:16:05.395: E/AndroidRuntime(6761): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myfinaltest.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfinaltest-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfinaltest-2, /vendor/lib, /system/lib]]
04-13 00:16:05.395: E/AndroidRuntime(6761):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-13 00:16:05.395: E/AndroidRuntime(6761):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
04-13 00:16:05.395: E/AndroidRuntime(6761):     ... 11 more

码:

package com.example.myfinaltest;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

AndroidManifest.xml中:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfinaltest"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

</manifest>

对于,values / styles.xml和values-v11 / styles.xml和values-v14 / styles.xml

所有3个xml的值都相同,但是我评论了App主题,因为我看到用Appcompat库构建时出错。

    <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.Light">
    </style>
-->

    <!-- Application theme. 
    <style name="AppTheme" parent="AppBaseTheme">
    </style>
-->
</resources>

检查您的AndroidManifest.xml,以查看您的活动是否定义如下。

<activity
    android:name="com.example.myfinaltest.MainActivity"
    android:label="@string/app_name" >
</activity>

在您的情况下,程序包名称可能不是“ com.example.myfinaltest”。

由于使用的是AppCompat并扩展了ActionBarActivity ,因此需要指定正确的主题。

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfinaltest"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

</manifest>

values/styles.xml

您可以删除所有它们, values/styles.xml 除外

<resources>

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
    </style>

</resources>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM