我的代码:
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)
答案 0 :(得分:0)
好的,我找到了解决办法,结果是doInBackground和onPostExecute之间的延迟,有一点延迟,并且很少有人赞扬这位舆论回到onPostExecute