0

当 doInBackground 尝试返回时,我的 AsyncTask 崩溃(在我的情况下为 json 对象),据说:源附件不包含文件 asynctask.class 的源我不知道我的代码有什么问题。谢谢!

我的代码:

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();
    }
}

}

我的 LogCat 是:

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)
4

1 回答 1

0

好的,我找到了解决方案,原因是 doInBackground 和 onPostExecute 之间的延迟,有一点延迟,经过几次赞扬,编译器回到 onPostExecute

于 2013-06-22T14:36:16.943 回答