不幸的是对话已停止

时间:2015-01-24 17:36:20

标签: android android-layout

我在我的代码中使用了对话框主题,但模拟器显示的是不幸的对话框已停止的消息。 我的AVD仿真器细节如下: Nexus 7 API 19 皮肤:HVGA

这是我的manifest.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.dialog"
        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" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Dialog">
             >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>`

这是我的main.java文件

package com.example.dialog;

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


Here is my log when I launched my app

    01-24 12:56:23.232: I/ActivityManager(383): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.dialog/.MainActivity} from pid 546
01-24 12:56:23.322: E/gralloc_goldfish(55): gralloc_alloc: Mismatched usage flags: 164 x 246, usage 333
01-24 12:56:23.322: W/GraphicBufferAllocator(55): alloc(164, 246, 1, 00000333, ...) failed -22 (Invalid argument)
01-24 12:56:23.322: E/(55): GraphicBufferAlloc::createGraphicBuffer(w=164, h=246) failed (Invalid argument), handle=0x0
01-24 12:56:23.322: E/BufferQueue(383): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
01-24 12:56:23.332: W/WindowManager(383): Screenshot failure taking screenshot for (164x246) to layer 21005
01-24 12:56:23.432: D/dalvikvm(383): GC_FOR_ALLOC freed 735K, 23% free 6131K/7904K, paused 74ms, total 84ms
01-24 12:56:23.452: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.452: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.452: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.452: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.462: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.462: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.462: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/KeypressStandard.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/KeypressDelete.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
01-24 12:56:23.472: E/SoundPool(383): error loading /system/media/audio/ui/KeypressReturn.ogg
01-24 12:56:23.472: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
01-24 12:56:23.482: E/SoundPool(383): error loading /system/media/audio/ui/KeypressInvalid.ogg
01-24 12:56:23.482: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
01-24 12:56:23.482: W/AudioService(383): onLoadSoundEffects(), Error -1 while loading samples
01-24 12:56:23.642: I/ActivityManager(383): Start proc com.example.dialog for activity com.example.dialog/.MainActivity: pid=1298 uid=10053 gids={50053}
01-24 12:56:23.692: D/dalvikvm(1298): Not late-enabling CheckJNI (already on)
01-24 12:56:24.172: D/AndroidRuntime(1298): Shutting down VM
01-24 12:56:24.172: W/dalvikvm(1298): threadid=1: thread exiting with uncaught exception (group=0xb2a2bba8)
01-24 12:56:24.242: E/AndroidRuntime(1298): FATAL EXCEPTION: main
01-24 12:56:24.242: E/AndroidRuntime(1298): Process: com.example.dialog, PID: 1298
01-24 12:56:24.242: E/AndroidRuntime(1298): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dialog/com.example.dialog.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.os.Handler.dispatchMessage(Handler.java:102)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.os.Looper.loop(Looper.java:136)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.app.ActivityThread.main(ActivityThread.java:5017)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at java.lang.reflect.Method.invokeNative(Native Method)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at java.lang.reflect.Method.invoke(Method.java:515)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at dalvik.system.NativeStart.main(Native Method)
01-24 12:56:24.242: E/AndroidRuntime(1298): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at com.example.dialog.MainActivity.onCreate(MainActivity.java:12)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.app.Activity.performCreate(Activity.java:5231)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-24 12:56:24.242: E/AndroidRuntime(1298):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
01-24 12:56:24.242: E/AndroidRuntime(1298):     ... 11 more
01-24 12:56:24.282: W/ActivityManager(383):   Force finishing activity com.example.dialog/.MainActivity
01-24 12:56:24.322: W/InputMethodManagerService(383): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b2f48420 attribute=null, token = android.os.BinderProxy@b2ff3050
01-24 12:56:24.852: W/ActivityManager(383): Activity pause timeout for ActivityRecord{b304dbc0 u0 com.example.dialog/.MainActivity t6 f}
01-24 12:56:29.172: I/Process(1298): Sending signal. PID: 1298 SIG: 9
01-24 12:56:29.182: I/ActivityManager(383): Process com.example.dialog (pid 1298) has died.
01-24 12:56:29.262: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.262: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.332: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.332: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.372: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
01-24 12:56:29.382: E/SoundPool(383): error loading /system/media/audio/ui/KeypressStandard.ogg
01-24 12:56:29.382: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
01-24 12:56:29.382: E/SoundPool(383): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-24 12:56:29.392: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
01-24 12:56:29.392: E/SoundPool(383): error loading /system/media/audio/ui/KeypressDelete.ogg
01-24 12:56:29.402: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
01-24 12:56:29.402: E/SoundPool(383): error loading /system/media/audio/ui/KeypressReturn.ogg
01-24 12:56:29.432: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
01-24 12:56:29.442: E/SoundPool(383): error loading /system/media/audio/ui/KeypressInvalid.ogg
01-24 12:56:29.442: W/AudioService(383): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
01-24 12:56:29.442: W/AudioService(383): onLoadSoundEffects(), Error -1 while loading samples
01-24 12:56:29.512: W/InputMethodManagerService(383): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b2d153c8 attribute=null, token = android.os.BinderProxy@b2ff3050

这是我的Styles.xml文件

<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">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

1 个答案:

答案 0 :(得分:0)

您继承ActionBarActivity(正如日志所示)要求您使用AppCompat主题。

styles.xml设置为:

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

修改

此外,在您的清单中删除此内容:

android:theme="@android:style/Theme.Dialog">

否则使用不同的活动类,例如Activity