最简单的HELLO WORLD不适用于仿真器

时间:2014-07-20 14:11:37

标签: android

我刚刚开发android开发。事实上,我是在今天下午早些时候开始的。我按照此链接中的说明操作。

https://developer.android.com/training/basics/firstapp/creating-project.html

我只是将其重命名为hello2。

除非我试图在AVD中运行它,否则一切看起来都很完美。我的logcat不断弹出一些错误。并且模拟器显示“不幸的是,hello2已停止。”

有人可以帮助我吗?

这是我的java文件

package com.example.hello2;

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

这是我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hello2"
    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>

这是我的logcat:

07-20 13:22:25.760: W/dalvikvm(960): threadid=1: thread exiting with uncaught exception (group=0xb3af1d70)
07-20 13:22:25.780: E/AndroidRuntime(960): FATAL EXCEPTION: main
07-20 13:22:25.780: E/AndroidRuntime(960): Process: com.example.hello2, PID: 960
07-20 13:22:25.780: E/AndroidRuntime(960): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hello2/com.example.hello2.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.os.Handler.dispatchMessage(Handler.java:102)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.os.Looper.loop(Looper.java:136)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.main(ActivityThread.java:5026)
07-20 13:22:25.780: E/AndroidRuntime(960):  at java.lang.reflect.Method.invokeNative(Native Method)
07-20 13:22:25.780: E/AndroidRuntime(960):  at java.lang.reflect.Method.invoke(Method.java:515)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-20 13:22:25.780: E/AndroidRuntime(960):  at dalvik.system.NativeStart.main(Native Method)
07-20 13:22:25.780: E/AndroidRuntime(960): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Activity.setContentView(Activity.java:1930)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.example.hello2.MainActivity.onCreate(MainActivity.java:13)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Activity.performCreate(Activity.java:5242)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-20 13:22:25.780: E/AndroidRuntime(960):  ... 11 more

我希望有人可以帮助我..

PS:抱歉英语不好。

3 个答案:

答案 0 :(得分:1)

当您使用ActionBarActivity时,为您的活动设置的目标SDK不适用于ActionBarActivity。更改API版本或仅使用扩展“活动”而不是“ActionBarActivity”

答案 1 :(得分:0)

您要定位哪种API?您可以在清单中查看。如果您的目标是API 20,请将其更改为19,它应该有效。

希望它有所帮助。

答案 2 :(得分:0)

嘿RED_x,如果我们删除它为我工作的目标sdk版本2 !!以后有问题吗?