Reputation: 13
Here is the code, sorry for my English.
The error is : NullPointerException
. One Activity Class "menu_fei", One class Cliente and One Interface for returned value.
public interface AsyncResponse {
void processFinish(String output);
}
public class Cliente extends AsyncTask<String, String, String> {
public AsyncResponse delegate = null; //
public Cliente(AsyncResponse delegate) {
this.delegate = delegate;
}
public Cliente(String type) {
this.excute();
}
// in method doInBackground return correctly string
protected void onPostExecute(String result) {
// Log.d("OutPut",result); // it's ok String!
if (result == null)
Log.d("OUTPUT", "NULL"); // for example
else
delegate.processFinish(result); // --- ERROR !! --- but result not NUll
}
}
public class Menu_fei extends Activity implements AsyncResponse {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cliente asyncTask =new Cliente(this);
asyncTask.delegate = this;
new Cliente("menu_fei");
}
}
Upvotes: 0
Views: 103
Reputation: 16833
Implement this constructor
public Cliente(AsyncResponse delegate) {
this.delegate = delegate;
this.execute();
}
'type' is no use here.
Calling
new Cliente(this);
will launch the task
Upvotes: 0
Reputation: 157447
Cliente asyncTask =new Cliente(this);
asyncTask.delegate = this;
new Cliente("menu_fei");
the problem with your code is that in the third line you are creating a new instance of the Cliente
without setting the delegate. To fix you can simply run
Cliente asyncTask =new Cliente(this);
asyncTask.execute();
Upvotes: 1