This might help someone also: How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?
I am calling method from another class in onPostExecute()
.
I assume that onPostExecute()
is called after doInBackground(String... params)
and that is right, according to documentation and debugger.
Calling the method:
protected void onPostExecute(String result) {
CreateHangOut crtHO = new CreateHangOut();
crtHO.createHangOut(result);
}
Part of method called, causing NPE (first line of method):
public void createHangOut(String location) {
String city=autocompleteTV.getText().toString();
}
Autocomplete TextView
(autocompleteTV
) is initialized onCreate of the activity.
Here is how I call AsyncTask
:
create.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new
HTTPRequest().execute((autocompleteTV.getText()).toString());
}
});
Method called onCreate (of activity from where button is clicked) :
private void initialize() {
gAPI= new GoogleAPIAutocomplete();
autocompleteTV = (AutoCompleteTextView)
findViewById(R.id.crtHOLocOptionsTV);
setUpAutocomplete();
create = (Button) findViewById(R.id.crtHOCreateBtn);
name =(EditText) findViewById(R.id.crtHONameET);
create.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new
HTTPRequest().execute((autocompleteTV.getText()).toString());
}
});
}