“Hello World”应用程序给予遗憾(app)已停止工作

时间:2014-08-08 08:51:39

标签: android avd

我尝试运行基本的“Hello World”应用程序但是即使应用程序安装在模拟器中,它也不会运行并提供消息

  

不幸的是,(app)已停止工作。

Mainactivity.java

public class MainActivity extends Activity {

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

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ebook.test.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

的AndroidManifest.xml

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

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

    <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>

我使用的是API 20,这是默认代码。谁能告诉我如何在模拟器中正确运行应用程序?

日志:

08-08 10:53:11.400: E/AndroidRuntime(865): FATAL EXCEPTION: main
08-08 10:53:11.400: E/AndroidRuntime(865): Process: com.example.help, PID: 865
08-08 10:53:11.400: E/AndroidRuntime(865):  at java.lang.reflect.Method.invokeNative(Native Method)
08-08 10:53:11.400: E/AndroidRuntime(865): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.help/com.example.help.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
08-08 10:53:11.400: E/AndroidRuntime(865):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
08-08 10:53:11.400: E/AndroidRuntime(865):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
08-08 10:53:11.400: E/AndroidRuntime(865):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
08-08 10:53:11.400: E/AndroidRuntime(865):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)

08-08 10:53:11.400: E/AndroidRuntime(865):  at java.lang.reflect.Method.invoke(Method.java:515)
08-08 10:53:11.400: E/AndroidRuntime(865):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
08-08 10:53:11.400: E/AndroidRuntime(865):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
08-08 10:53:11.400: E/AndroidRuntime(865):  at dalvik.system.NativeStart.main(Native Method)
08-08 10:53:11.400: E/AndroidRuntime(865): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
08-08 10:53:11.400: E/AndroidRuntime(865):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
08-08 10:53:11.400: E/AndroidRuntime(865):  at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
08-08 10:53:11.400: E/AndroidRuntime(865):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
08-08 10:53:11.400: E/AndroidRuntime(865):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
08-08 10:53:11.400: E/AndroidRuntime(865):  at android.app.Activity.setContentView(Activity.java:1930)
08-08 10:53:11.400: E/AndroidRuntime(865):  at com.example.help.MainActivity.onCreate(MainActivity.java:14)
08-08 10:53:11.400: E/AndroidRuntime(865):  at android.app.Activity.performCreate(Activity.java:5242)
08-08 10:53:11.400: E/AndroidRuntime(865):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-08 10:53:11.400: E/AndroidRuntime(865):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
08-08 10:53:11.400: E/AndroidRuntime(865):  ... 11 more

0 个答案:

没有答案