-
Null Pointer Exception Error in Android App
almost 4 years ago
-
over 2 years ago
I agree with @programmer
ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
Re declaring pDialog has a local variable, overshadows the instance variable and prevents it from being initialized. Therefore the solution his to just initialize it.
pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false); -
-
almost 4 years ago
Define pDialog as a public class member, right now it's defined local member. -
-
almost 4 years ago
Make public pDialog instead private pDialog, otherwise you have to create a getter and setter -
-
almost 4 years ago
Change
b1.setOnClickListener(this); ProgressDialog pDialog = new ProgressDialog(this); pDialog.setMessage("Loading...");
to
b1.setOnClickListener(this); pDialog = new ProgressDialog(this); pDialog.setMessage("Loading...");
pDialog must be class member, in you case you shadow it with a local variable.
-
4 Answer(s)