2013-03-26 6 views
0

대화 상자에 사용자 정의 레이아웃을 사용하고 있습니다. 이것은 util java (활동이 아님)의 메소드입니다.대화 상자를 표시 할 때 예외가 발생했습니다.

public void showLoadingProgress(String msg){ 
    Log.d("EditorUtil", "show loading progress"+progressDialog);//No i18n 
    if(progressDialog!=null && progressDialog.isShowing()){ 
     TextView message = (TextView)progressDialog.findViewById(R.id.progressmsg); 
     message.setText(msg); 
     return; 
    } 

Context context = EditorActivity.getActivity().getApplicationContext(); 
progressDialog = new Dialog(EditorActivity.getActivity().getApplicationContext()); 
progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
progressDialog.setCancelable(false); 
progressDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 
progressDialog.setContentView(R.layout.customprogress); 

TextView message = (TextView)progressDialog.findViewById(R.id.progressmsg); 
message.setText(msg); 

progressDialog.show(); 
Log.d("",progressDialog.isShowing()+""); //No i18n 

}

내가 대신 대화 생성자에 응용 프로그램 컨텍스트의 현재 활동 상황에 합격해야합니다 호출 비 활동에서 progressDialog을 보여주는

03-26 11:23:41.672: W/dalvikvm(8034): threadid=1: thread exiting with uncaught exception (group=0x40c2d930) 
03-26 11:23:41.732: E/AndroidRuntime(8034): FATAL EXCEPTION: main 
03-26 11:23:41.732: E/AndroidRuntime(8034): java.lang.IllegalStateException: Could not execute method of the activity 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.view.View$1.onClick(View.java:3597) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.view.View.performClick(View.java:4202) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.view.View$PerformClick.run(View.java:17340) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.os.Handler.handleCallback(Handler.java:725) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.os.Handler.dispatchMessage(Handler.java:92) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.os.Looper.loop(Looper.java:137) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.app.ActivityThread.main(ActivityThread.java:5039) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at java.lang.reflect.Method.invokeNative(Native Method) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at java.lang.reflect.Method.invoke(Method.java:511) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at dalvik.system.NativeStart.main(Native Method) 
03-26 11:23:41.732: E/AndroidRuntime(8034): Caused by: java.lang.reflect.InvocationTargetException 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at java.lang.reflect.Method.invokeNative(Native Method) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at java.lang.reflect.Method.invoke(Method.java:511) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.view.View$1.onClick(View.java:3592) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  ... 11 more 
03-26 11:23:41.732: E/AndroidRuntime(8034): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.view.ViewRootImpl.setView(ViewRootImpl.java:571) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) 
03-26 11:23:41.732: E/AndroidRuntime(8034):  at android.app.Dialog.show(Dialog.java:281 
+0

)는 (유 EditorActivity.getActivity() '대신 EditorActivity.getActivity'의'시도해야 .getApplicationContext()' –

답변

1

같은 예외를 얻었다. 하나 개 이상의 매개 변수를 추가하여 showLoadingProgress에 작업 콘텍스트를 전달할 수

public void showLoadingProgress(String msg,Context context){ 

//..... 
progressDialog = new Dialog(context); 
//..... 

} 

지금 showLoadingProgress 방법 두번째 파라미터로 EditorActivity.getActivity() 전달

관련 문제