0

HI when a new a alert dialog in android app, and there is a null point exception, saying that the viewroot can't get context, and the return of context is null. so has anyone meet the same problem. and give me some help. thx.

2
  • 1
    Please post the codes that you have here. Commented Apr 26, 2012 at 2:43
  • also put code how you are creating dialog Commented Apr 26, 2012 at 2:46

2 Answers 2

2

You shouldn't use getapplicationcontext() for alertdialog box. Instead of this, Use the activity class name.

if your activity name is AlertBuilderActivity use

          (AlertBuilderActivity.this) for context
Sign up to request clarification or add additional context in comments.

Comments

0
AlertDialog alertDialog = new AlertDialog.Builder(YourActivity.this).create(); 

for creating alert dialog you cant use getApplicationContext() you must use as in the above line.

AlertDialog alertDialog = new AlertDialog.Builder(getApplicationContext()).create();

2 Comments

HI Agarwal , thanks a lot. Your method could solve the dialog creating in apk. Because there is a looper in this main thread, then dialog could be showed.
^_^, sorry for late reply. I mean that you method works well in apk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.