class GetDetails extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(EditProduct.this);
pDialog.setMessage("Chargement. Patienter ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... params) {
runOnUiThread(new Runnable() {
public void run() {
int success;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("pid", pid));
JSONObject json = jsonParser.makeHttpRequest(
url_product_detials, "GET", params);
Log.d("Single Product Details", json.toString());
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
JSONArray productObj = json.getJSONArray(TAG_PRODUCT);
JSONObject product = productObj.getJSONObject(0);
txtName = (EditText) findViewById(R.id.inputName);
txtLongi = (EditText) findViewById(R.id.inputLongi);
txtLati = (EditText) findViewById(R.id.inputLati);
txtRegion = (EditText) findViewById(R.id.inputRegion);
txtName.setText(product.getString(TAG_NAME));
txtLongi.setText(product.getString(TAG_PRICE));
txtLati.setText(product.getString(TAG_DESCRIPTION));
txtRegion.setText(product.getString(TAG_LOCATION));
}else{
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
}
日志猫:
11-12 22:42:12.552: E/AndroidRuntime(1100): FATAL EXCEPTION: main
11-12 22:42:12.552: E/AndroidRuntime(1100): android.os.NetworkOnMainThreadException
11-12 22:42:12.552: E/AndroidRuntime(1100): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
11-12 22:42:12.552: E/AndroidRuntime(1100): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
11-12 22:42:12.552: E/AndroidRuntime(1100): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
11-12 22:42:12.552: E/AndroidRuntime(1100): at libcore.io.IoBridge.connect(IoBridge.java:112)
11-12 22:42:12.552: E/AndroidRuntime(1100): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
11-12 22:42:12.552: E/AndroidRuntime(1100): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
11-12 22:42:12.552: E/AndroidRuntime(1100): at java.net.Socket.connect(Socket.java:842)
11-12 22:42:12.552: E/AndroidRuntime(1100): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
11-12 22:42:12.552: E/AndroidRuntime(1100): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
11-12 22:42:12.552: E/AndroidRuntime(1100): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
11-12 22:42:12.552: E/AndroidRuntime(1100): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
11-12 22:42:12.552: E/AndroidRuntime(1100): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
11-12 22:42:12.552: E/AndroidRuntime(1100): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-12 22:42:12.552: E/AndroidRuntime(1100): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-12 22:42:12.552: E/AndroidRuntime(1100): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-12 22:42:12.552: E/AndroidRuntime(1100): at com.example.androidhive.JSONParser.makeHttpRequest(JSONParser.java:62)
11-12 22:42:12.552: E/AndroidRuntime(1100): at fitness.coter.serveur.EditProduct$GetPharmacieDetails$1.run(EditProduct.java:135)
11-12 22:42:12.552: E/AndroidRuntime(1100): at android.os.Handler.handleCallback(Handler.java:725)
11-12 22:42:12.552: E/AndroidRuntime(1100): at android.os.Handler.dispatchMessage(Handler.java:92)
11-12 22:42:12.552: E/AndroidRuntime(1100): at android.os.Looper.loop(Looper.java:137)
11-12 22:42:12.552: E/AndroidRuntime(1100): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-12 22:42:12.552: E/AndroidRuntime(1100): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 22:42:12.552: E/AndroidRuntime(1100): at java.lang.reflect.Method.invoke(Method.java:511)
11-12 22:42:12.552: E/AndroidRuntime(1100): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-12 22:42:12.552: E/AndroidRuntime(1100): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-12 22:42:12.552: E/AndroidRuntime(1100): at dalvik.system.NativeStart.main(Native Method)
11-12 22:42:18.021: I/Process(1100): Sending signal. PID: 1100 SIG: 9
11-12 22:42:20.212: E/Trace(1130): error opening trace file: No such file or directory (2)