开发者

DialogExample program of android crashes

开发者 https://www.devze.com 2023-03-27 13:21 出处:网络
ERROR : The Application DialogSample has stopped unexpectedly.please try again. public class DialogSampleActivity extends Activity {

ERROR : The Application DialogSample has stopped unexpectedly.please try again.

 public class DialogSampleActivity extends Activity {

    static final int DIALOG_PAUSED_ID = 0;
    static f开发者_如何学Pythoninal int DIALOG_GAMEOVER_ID = 1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);    

        Context mContext = getApplicationContext();
        Dialog dialog = new Dialog(mContext);

        dialog.setContentView(R.layout.custom_dialog);
        dialog.setTitle("Custom Dialog");

        TextView text = (TextView) dialog.findViewById(R.id.text);
        text.setText("Hello, this is a custom dialog!");
        Imenter code hereageView image = (ImageView) dialog.findViewById(R.id.image);
        image.setImageResource(R.drawable.android);

        dialog.show();

    }

   }

08-17 11:13:02.777: DEBUG/AndroidRuntime(594): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
08-17 11:13:02.787: DEBUG/AndroidRuntime(594): CheckJNI is ON
08-17 11:13:05.166: DEBUG/AndroidRuntime(594): Calling main entry com.android.commands.pm.Pm
08-17 11:13:05.277: DEBUG/AndroidRuntime(594): Shutting down VM
08-17 11:13:05.306: INFO/AndroidRuntime(594): NOTE: attach of thread 'Binder Thread #3' failed
08-17 11:13:05.327: DEBUG/dalvikvm(594): GC_CONCURRENT freed 100K, 72% free 296K/1024K, external 0K/0K, paused 9ms+20ms
08-17 11:13:05.327: DEBUG/jdwp(594): Got wake-up signal, bailing out of select
08-17 11:13:05.327: DEBUG/dalvikvm(594): Debugger has detached; object registry had 1 entries
08-17 11:13:06.377: DEBUG/AndroidRuntime(604): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
08-17 11:13:06.377: DEBUG/AndroidRuntime(604): CheckJNI is ON
08-17 11:13:08.217: DEBUG/AndroidRuntime(604): Calling main entry com.android.commands.am.Am
08-17 11:13:08.338: INFO/ActivityManager(103): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.DialogSample/.DialogSampleActivity } from pid 604
08-17 11:13:08.477: INFO/ActivityManager(103): Start proc com.DialogSample for activity com.DialogSample/.DialogSampleActivity: pid=612 uid=10037 gids={}
08-17 11:13:08.486: DEBUG/AndroidRuntime(604): Shutting down VM
08-17 11:13:08.548: INFO/AndroidRuntime(604): NOTE: attach of thread 'Binder Thread #3' failed
08-17 11:13:08.597: DEBUG/dalvikvm(604): GC_CONCURRENT freed 102K, 69% free 319K/1024K, external 0K/0K, paused 3ms+4ms
08-17 11:13:08.676: DEBUG/jdwp(604): Got wake-up signal, bailing out of select
08-17 11:13:08.676: DEBUG/dalvikvm(604): Debugger has detached; object registry had 1 entries
08-17 11:13:09.416: DEBUG/dalvikvm(33): GC_EXPLICIT freed 10K, 53% free 2537K/5379K, external 1625K/2137K, paused 828ms
08-17 11:13:09.676: DEBUG/dalvikvm(33): GC_EXPLICIT freed <1K, 53% free 2537K/5379K, external 1625K/2137K, paused 264ms
08-17 11:13:09.847: DEBUG/dalvikvm(33): GC_EXPLICIT freed <1K, 53% free 2537K/5379K, external 1625K/2137K, paused 162ms
08-17 11:13:12.127: DEBUG/dalvikvm(612): GC_EXTERNAL_ALLOC freed 53K, 53% free 2559K/5379K, external 1872K/2137K, paused 98ms
08-17 11:13:12.226: DEBUG/AndroidRuntime(612): Shutting down VM
08-17 11:13:12.226: WARN/dalvikvm(612): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-17 11:13:12.287: ERROR/AndroidRuntime(612): FATAL EXCEPTION: main
08-17 11:13:12.287: ERROR/AndroidRuntime(612): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.DialogSample/com.DialogSample.DialogSampleActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.os.Looper.loop(Looper.java:123)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.ActivityThread.main(ActivityThread.java:3647)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at java.lang.reflect.Method.invokeNative(Native Method)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at java.lang.reflect.Method.invoke(Method.java:507)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at dalvik.system.NativeStart.main(Native Method)
08-17 11:13:12.287: ERROR/AndroidRuntime(612): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at com.android.internal.app.AlertController.installContent(AlertController.java:199)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.AlertDialog.onCreate(AlertDialog.java:251)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.Dialog.dispatchOnCreate(Dialog.java:307)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.Dialog.show(Dialog.java:225)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at com.DialogSample.DialogSampleActivity.onCreate(DialogSampleActivity.java:41)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
08-17 11:13:12.287: ERROR/AndroidRuntime(612):     ... 11 more
08-17 11:13:12.339: WARN/ActivityManager(103):   Force finishing activity com.DialogSample/.DialogSampleActivity
08-17 11:13:12.897: WARN/ActivityManager(103): Activity pause timeout for HistoryRecord{408aa0a8 com.DialogSample/.DialogSampleActivity}
08-17 11:13:24.800: WARN/ActivityManager(103): Activity destroy timeout for HistoryRecord{408aa0a8 com.DialogSample/.DialogSampleActivity}
08-17 11:13:29.808: INFO/Process(612): Sending signal. PID: 612 SIG: 9
08-17 11:13:29.927: WARN/InputManagerService(103): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40831b48
08-17 11:13:30.716: INFO/ActivityManager(103): Process com.DialogSample (pid 612) has died.

this was the logcat for the previous code


replace this line Dialog dialog = new Dialog(mContext);

AlertDialog dialog = new AlertDialog.Builder(mContext).create();


try this:

private AlertDialog show(){
            LayoutInflater inflator = LayoutInflater.from(mContext);
            View view = inflator.inflate(R.layout.custom_dialog, null);
            TextView text = (TextView) view.findViewById(R.id.text);
            text.setText("Hello, this is a custom dialog!");
            ImageView image = (ImageView) view.findViewById(R.id.image);
            image.setImageResource(R.drawable.android);


            return new AlertDialog.Builder(Search.this)
            .setView(view)
            .setTitle("Custom Dialog")
            .show();
        }

call this function from your code and it will show the dialog....It is working at my end.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号