Das Problem ist das runOnUiThread innerhalb der AsyncTask. Die Exception entsteht, weil Sie den UI-Thread zu lange belegen. Eine AsyncTask ist richtig, aber der Aufruf von runOnUiThread darin ist widersinnig, da die Ausführung dann nicht mehr asynchron ist.
- Entfernen Sie den
runOnUiThread-Teil ausdoInBackground(). - Speichern Sie die anzuzeigenden Werte als Member der Async-Task oder als Ergebnis-Parameter.
- Setzen Sie die
setText-Aufrufe inpostExecute, denn dort läuft der Code auf dem UI-Thread.
Etwa so:
/** * Background Async Task to Get complete person details * */ class CheckLogin extends AsyncTask<String, String, String> { JSONArray productObj; /** * Before starting background thread Show Progress Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(AndroidPHPConnectionDemo.this); pDialog.setMessage("Loading person details. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } /** * Getting person details in background thread * */ @Override protected String doInBackground(String... arg0) { // TODO Auto-generated method stub int success; try { // Building Parameters List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("pid", pid)); // getting person details by making HTTP request // Note that person details url will use GET request JSONObject json = jsonParser.makeHttpRequest( url_check_login, "GET", params); // check your log for json response Log.d("Single person Details", json.toString()); // json success tag success = json.getInt(TAG_SUCCESS); if (success == 1) { // successfully received person details productObj = json .getJSONArray(TAG_PERSON); // JSON Array } else { // product with pid not found } } catch (JSONException e) { e.printStackTrace(); } } return null; } /** * After completing background task Dismiss the progress dialog * **/ protected void onPostExecute(String file_url) { // dismiss the dialog once got all details if ( productObj != null ) { // get first product object from JSON Array JSONObject person = productObj.getJSONObject(0); et.setText(person.getString(TAG_NAME)); pass.setText(person.getString(TAG_pass)); Log.e("success in login", "SUCCESS IN LOGIN"); } pDialog.dismiss(); } }