0

my AsyncTask crashed when doInBackground try to return (json object in my case), It's said : the source attachment does not contain the source for the file asynctask.class i don't know what's wrong with my code. Thanks!

my code:

public class CreateNetworkTask extends AsyncTask<String, Integer, JSONObject> {

CreateNetwork activity;
//private ProgressDialog progDialog;

public CreateNetworkTask(CreateNetwork activity) {
    this.activity = activity;
}

@Override
protected JSONObject doInBackground(String... params) {
    CommunicationModule comm = new CommunicationModule();
    JSONObject jobjNewNetworkDetails = new JSONObject();
    try {

        jobjNewNetworkDetails.put("name",activity.networkName );
        jobjNewNetworkDetails.put("description",activity.descrpNetwork );
        jobjNewNetworkDetails.put("network_type", "Personal");
        // only for debug
        activity.locType = new String("circle");
        jobjNewNetworkDetails.put("user_id", LoginActivity.myUser.getId());
        jobjNewNetworkDetails.put("location_type", activity.locType);
        if (activity.flag == 0){
            //jobjNewNetworkDetails.put("center", center);
            jobjNewNetworkDetails.put("longitude", activity.Lng);
            jobjNewNetworkDetails.put("latitude", activity.Lat);
            jobjNewNetworkDetails.put("radius", activity.radius);
        }
        else{
            jobjNewNetworkDetails.put("polygonPoints", activity.networkLoc);
        }
    } 
    catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

    JSONObject jobj = comm.jsPackForCreateNetwork(activity.client, CreateNetwork.URL_STRING, jobjNewNetworkDetails,activity.context) ;

    return jobj;
}

@Override
protected void onPreExecute() {
    // TODO Auto-generated method stub
    super.onPreExecute();
    activity.tvHttp.setText("data loading.........");
    //progDialog = ProgressDialog.show(activity.context, "On progress", "Try to create your Network");
}


protected void onPostExecute(JSONObject jobj) {
    //progDialog.dismiss();
    if(jobj == null){
        activity.tvHttp.setText("Error, try to reload!");
        return;
    }

    //progDialog.dismiss();
    try {
        activity.networkIdFromServer = jobj.getString("network_id").toString();
    } 

    catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

my LogCat is:

E/Debug Error(21124): End of input at character 0 of 
E/Debug Error(21124): org.json.JSONException: End of input at character 0 of 
E/Debug Error(21124):   at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
E/Debug Error(21124):   at org.json.JSONTokener.nextValue(JSONTokener.java:97)
E/Debug Error(21124):   at org.json.JSONObject.<init>(JSONObject.java:154)
E/Debug Error(21124):   at org.json.JSONObject.<init>(JSONObject.java:171)
E/Debug Error(21124):   at            org.example.communication.CommunicationModule.jsPackForCommentUpdate(CommunicationModule.java:437)
E/Debug Error(21124):   at org.example.communication.CreateNewUserTask.doInBackground(CreateNewUserTask.java:39)
E/Debug Error(21124):   at org.example.communication.CreateNewUserTask.doInBackground(CreateNewUserTask.java:1)
E/Debug Error(21124):   at android.os.AsyncTask$2.call(AsyncTask.java:287)
E/Debug Error(21124):   at java.util.concurrent.FutureTask.run(FutureTask.java:234)
E/Debug Error(21124):   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
E/Debug Error(21124):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
E/Debug Error(21124):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
E/Debug Error(21124):   at java.lang.Thread.run(Thread.java:856)
elik_sr
  • 105
  • 2
  • 6

1 Answers1

0

Ok, i found the solution, the resone was the delay between doInBackground and onPostExecute, there is a small delay and after few commends the compailer come back to the onPostExecute

elik_sr
  • 105
  • 2
  • 6