不幸的是,AndroidFirst已经停止了

时间:2014-08-29 05:54:35

标签: android android-activity android-emulator

我是Android应用程序的初学者刚刚开始建立第一个" HelloWorld"应用程序。我按照官方教程和设计模拟器。但是,当我运行它时,模拟器说"不幸的是,AndroidFirst已停止"。我环顾四周,但不同的解决方案并没有帮助。我是Android的初学者,因此无法找到错误或错误的错误。

以下是logCat:

08-29 05:16:58.629: W/dalvikvm(1934): VFY: unable to resolve static field 1864 (ActionBarWindow) in Landroid/support/v7/appcompat/R$styleable;
08-29 05:16:58.629: D/dalvikvm(1934): VFY: replacing opcode 0x62 at 0x0004
08-29 05:16:58.649: D/AndroidRuntime(1934): Shutting down VM
08-29 05:16:58.649: W/dalvikvm(1934): threadid=1: thread exiting with uncaught exception (group=0xb1daece8)
08-29 05:16:58.669: E/AndroidRuntime(1934): FATAL EXCEPTION: main
08-29 05:16:58.669: E/AndroidRuntime(1934): Process: com.example.androidfirst, PID: 1934
08-29 05:16:58.669: E/AndroidRuntime(1934): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:106)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at com.example.androidfirst.MainActivity.onCreate(MainActivity.java:13)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.app.Activity.performCreate(Activity.java:5242)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.app.ActivityThread.access$800(ActivityThread.java:138)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.os.Looper.loop(Looper.java:136)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at android.app.ActivityThread.main(ActivityThread.java:5026)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at java.lang.reflect.Method.invokeNative(Native Method)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at java.lang.reflect.Method.invoke(Method.java:515)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
08-29 05:16:58.669: E/AndroidRuntime(1934):     at dalvik.system.NativeStart.main(Native Method)
08-29 05:21:58.843: I/Process(1934): Sending signal. PID: 1934 SIG: 9

MainActivity.java代码:

package com.example.androidfirst;

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.androidfirst"
    android:versionCode="1"
    android:versionName="1.0" >

    <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=".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>

我非常感谢你们!

2 个答案:

答案 0 :(得分:1)

需要Android支持库

看到这张图片:

enter image description here

然后只需将v7紧凑库项目导入您的工作区并将其作为库添加到您的项目中

您可以在目录中存在SDK的sdk\extras\android\support\v7\appcompat中找到它。

导入后,选择项目右键单击 - &gt; 属性 - &gt; Android - &gt; 添加 - &gt; 选择 app compact

点击确定

答案 1 :(得分:0)

我下载API-19&amp;重新创建了AVD。在第一次尝试时,AVD将“Hello World”显示为模拟器上的默认文本。