When I try to show a working dialog for an asynctask i get the following errors:
java.lang.reflect.InvocationTargetException
java.lang.NullPointerException
The code of the activity and asynctask is:
public class MainActivity extends Activity {
private ControlLogin ctlLogin;
private ProgressDialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
ctlLogin = (ControlLogin)findViewById(R.id.controlLogin);
ctlLogin.setOnLoginListener(new OnLoginListener()
{
@Override
public void onLogin(String email, String password, Boolean saveAccount){
ProgressDialog dialog = new ProgressDialog(getApplicationContext());
dialog.setMessage("Signing...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
new Login().execute(email, password);
}
});
}
public class Login extends AsyncTask<String, Float, CloudApp> {
protected void onPreExecute(){
dialog.show();
}
@Override
protected CloudApp doInBackground(String... arg0) {
CloudApp api = new CloudAppImpl(arg0[0], arg0[1]);
return api;
}
protected void onPostExecute(CloudApp api){
dialog.dismiss();
try {
CloudAppAccount acc = api.getAccountDetails();
Toast toast = Toast.makeText(getBaseContext(), "test: " + acc.getEmail(), Toast.LENGTH_LONG);
toast.show();
} catch (CloudAppException e) {
e.printStackTrace();
}
}
}
}
Any help??? Thanks!!
You are hiding your member
dialogin your code by defining a local variabledialogin youronLogin(...)method. Because of this,dialogis never initialized to anything and that is why you get an NPE in yourLoginclass.