2011-08-11 4 views
0

오류 : 응용 프로그램 DialogSample이 예기치 않게 중지되었습니다. 다시 시도하십시오. 안드로이드 충돌 DialogExample 프로그램

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: [email protected] 
08-17 11:13:30.716: INFO/ActivityManager(103): Process com.DialogSample (pid 612) has died. 

public class DialogSampleActivity extends Activity { 

    static final int DIALOG_PAUSED_ID = 0; 
    static final 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(); 

    } 

    } 

는 이전 코드

+0

무엇이 logcat이 표시됩니까? – ngesh

답변

0

이 시도이 줄을 교체했다 :

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

코드에서이 함수를 호출하면 대화 상자가 표시됩니다.

+0

> 코드가 작동 중입니다. 이전 코드로 prob를 찾았습니까? – Britto

+0

왜 작동하지 않았는지 알아낼 수 없었습니다 .... 지금 대답을 받아 들일 수 있습니다 .. –

+0

감사합니다 .. 내가 친절하게도 알려 주신 오류를 우연히 만났을 경우. – Britto

1

에 대한 로그 캣이 Dialog dialog = new Dialog(mContext);

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

나는 아직 프로그램을 변경했습니다. – Britto

+0

logcat에 무엇이 표시됩니까? –

관련 문제