Monday 15 August 2011

java - android.os.NetworkOnMainThreadException error even when running in AsyncTask -


While trying to connect me to the Internet, Android met. NetworkMonthandThreaded Expression error is occurring. I know that the above versions of Android (after Honeycomb) do not allow you to do Network IO on the UI thread, so I am using Ascot on the code. There is no error, but when it runs, then Android OS. Networks Onthatus Exception Error Code: Public Zero (Bundle Saved InstantState) on Creating {super.onCreate (SavedInstanceState); SetContentView (R.layout.mainactivity); New GetProductDetails () carry about (); } Class GetProductDetails asyncTask and lt; String, string, string & gt; {/ ** * Show progress dialog before starting background thread * * / @ Override Preserve Zero on PreExecute () {super.onPreExecute (); PDialog = new progression Diolog (main activity.); PDialog.setMessage ("Please wait while loading product details ..."); PDialog.setIndeterminate (wrong); PDialog.setCancelable (true); PDialog.show (); } / ** * Get product details in background thread * * / protected string doInBackground (string ... parameter) // // Update OD from background thread run ONUTHHADD (NEW RUNNABLE) (public wired run) {// success For Tag Ent Success, // {} Building Parameter List & lt; nameValuePair & gt; Parameters = New Array List & lt; nameValuePair & gt; (); params.add (New BasicNameValuePair ("pid", pid) ); // Receiving product details by requesting HTTP note that the product The URL will use the GET request JSONObject json = jsonParser.makeHttpRequest (url_product_details, "GET", params); // Check your log for json feedback logs ("Single Product Details", json.toString ()); // Json success tag success = json.getInt (TAG_SUCCESS); if (success == 1) {// successfully get product object before product description JSONArray product Obj = json .getJSONArray (TAG_PRODUCT); // JSON Array // JSON Array JSONObject Product = Products Obj.GadgetsSONObject (0); TCTNM = (Edit Text) FindUBID ( Rkaid.ankprogram); TSTPRICR = (edit text) Find VVBIID (R.I.InProp.); TxtDesc = Find (edit text) VVBIID (RIDINPDC); Product data displayed in // EditText txtName.setText (product.getString (TAG_NAME)); TxtPrice.setText (product.getString (TAG_PRICE)); TxtDesc.setText (product.getString (TAG_DESCRIPTION)); } Else {product with pid not found}} hold (JasonXExation E) {E.PintstacksTrace (); }}}); Return tap; } / ** * Dismiss progress dialog after completing background work ** ** / Protected void onPostExecute (string file_url) {// Dismiss dialog once all pDialog.dismiss () got found; }}

I have read that its possible solution is using the Strictcode policy, but I am reluctant to use it because it is only recommended in the development environment. What is the problem here?

What's the problem here?

From runnab to runOnUiThread () .

, RunOnUI and Fread () and Runnabal . Place the network code in doInBackground () . Update your code to onPostExecute () . You pass data from doInBackground () to onPostExecute () from doInBackground () return value (which is OnPostExecute () < / Code>) or data member from inside asyncTask .

No comments:

Post a Comment