case R.id.button_next_question:
if ((this.question_number > -1 + this.total_question) || (this.question_number == -1 + this.total_question))
{
new AlertDialog.Builder(getActivity().getApplicationContext()).setTitle("Thank you").show();
}
我想在项目完成问题列表时显示对话框,但是如果执行后如果执行则会出现以下错误
07-08 06:15:53.775: E/AndroidRuntime(1327): FATAL EXCEPTION: main
07-08 06:15:53.775: E/AndroidRuntime(1327): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.app.Dialog.show(Dialog.java:281)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
07-08 06:15:53.775: E/AndroidRuntime(1327): at info.androidhive.slidingmenu.CommunityFragment.onClick(CommunityFragment.java:120)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.view.View.performClick(View.java:4204)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.view.View$PerformClick.run(View.java:17355)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.os.Handler.handleCallback(Handler.java:725)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.os.Handler.dispatchMessage(Handler.java:92)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.os.Looper.loop(Looper.java:137)
07-08 06:15:53.775: E/AndroidRuntime(1327): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-08 06:15:53.775: E/AndroidRuntime(1327): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 06:15:53.775: E/AndroidRuntime(1327): at java.lang.reflect.Method.invoke(Method.java:511)
07-08 06:15:53.775: E/AndroidRuntime(1327): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-08 06:15:53.775: E/AndroidRuntime(1327): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-08 06:15:53.775: E/AndroidRuntime(1327): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
Thank for your reply
finally i got the solution & its working
if ((this.question_number > -1 + this.total_question) || (this.question_number == -1 + this.total_question))
{
LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View v1 =inflater.inflate(R.layout.dialog_layout, null);
new AlertDialog.Builder(getActivity()).setTitle("Thank you")
.setView(v1)
.show();
}