I'm having trouble starting my mainActivity after I have gotten a response from a httpUrlConnection. Here is my onPostExecute method
protected void onPostExecute(String[] result) {
serv.httphelper.handleResults(result);
}
In the method handleResult() im handling the response code. If the response code is 200 i want to run a new method inside my loginActivity class
public void handleResults(String[] result) {
status = result[0].toString();
instructions = result[1].toString();
jsonString = result[2];
Log.d("DEBUG", status);
if (status.equals("200")) {
serv.loginActivity.proceed();
} else if (status.equals("400")) {
serv.loginActivity.loginError();
} else if (status.equals("401")) {
serv.loginActivity.loginError();
}
}
When i try to start a new activity from the proceed() method i get a nullpointerexception
public void proceed(){
startActivity(new Intent (LoginActivity.this, MainActivity.class));
Log.d("TEST", "Proceed success");
}
My service class for anyone wondering:
public class Service {
public static HttpHelper httphelper = new HttpHelper();
public static HttpConnect conn = new HttpConnect();
public static LoginActivity loginActivity = new LoginActivity();
}
And here is my logCat:
Thanks in advance!
Your problem is when you start the activity at the line:
startActivity(new Intent (LoginActivity.this, MainActivity.class));
Well, you creates an intent that tries to get to LoginActivity.this
which probably does not exists!
Instead of this, you have to give an instance of a real activity that is currently running.
A solution that I can suggest you is to pass to proceed()
the instance of the currently running activity and put it instead of LoginActivity.this
.
In case you don't have a current activity, try to put your application's context instead and add it a flag of a new task.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments