Dialog throwing "Unable to add window — token null is not for an application” Error
This is a common problem, you can not reach the context first and therefore it is null. What
you need to do here is that if you use "ActivityName.this" instead of
getApplicationContext(),context etc. your problem will be resolved.
Like this;
Like this;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This is a common problem, you can not reach the context first and therefore it is null. | |
What you need to do here is that if you use "ActivityName.this" instead of getApplicationContext(), | |
context etc. your problem will be resolved. | |
*/ | |
//For example Alert Dialog; | |
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); //Activity name | |
alertDialog.setMessage("Test Messages"); | |
alertDialog.setPositiveButton("OK", listener); | |
AlertDialog alert = alertDialog.create(); | |
alert.show(); |
Yorumlar
Yorum Gönder