Note that there are some explanatory texts on larger screens.

plurals
  1. POonPostExecute method never get called in AsyncTask
    primarykey
    data
    text
    <p>I'm trying to fetch some data from db server. I understood I can't excute the network job on UI Main thread. the solution I found is AsyncTask. I override two method(onPostExecute, doInBackground), but after doInBackground, onPostExecute never called, and my android phone(galaxy s2) force my app to stop. where is the wrong place?</p> <pre><code>public class MainActivity extends Activity { EditText mResult; private static final String TAG = "JSON"; String Json; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mResult = (EditText)findViewById(R.id.result); Button btn = (Button)findViewById(R.id.parse); btn.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v){ getHtml("http://192.168.0.12/index.php"); //Json = getHtml("http://192.168.0.12/index.php"); Log.i(TAG, Integer.toString(5)); Log.i(TAG, Json); Log.i(TAG, Integer.toString(6)); try{ String Result = "member list: \n"; JSONArray ja = new JSONArray(Json); for(int j=0; j&lt;ja.length(); j++) { JSONObject order = ja.getJSONObject(j); Result +="ID : " + order.getInt("id") + " " + "number : " + order.getInt("gisoo")+ " " + "name : " + order.getString("name")+ " " + "sex : " + order.getString("sex")+ " " + "age : " + order.getInt("age")+ " " + "school : " + order.getString("university")+ " " + "phone : " + order.getString("phone")+ " " + "no : " + order.getInt("numberOfVolunteer")+ " " + "lastlogin : " + order.getString("lastLogin")+ " " + "lastactivity : " + order.getString("lastVolunteer")+ " " + "message : " + order.getString("message")+ "\n\n"; } mResult.setText(Result); } catch(JSONException e) { Toast.makeText(v.getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } } }); } private void getHtml(String url) { new ProcessHtmlTask().execute(url); } private class ProcessHtmlTask extends AsyncTask&lt;String, Void, String&gt;{ @Override protected void onPostExecute(String JSON){ Log.i(TAG, Integer.toString(8)); //I couldn't see number 8 in log. Json = JSON; return; } @Override protected String doInBackground(String... addr){ StringBuilder jsonHtml = new StringBuilder(); HttpURLConnection conn; try{ URL url = new URL(addr[0]); conn = (HttpURLConnection)url.openConnection(); if(conn != null) { conn.setConnectTimeout(10000); conn.setUseCaches(true); int n = conn.getResponseCode(); Log.i(TAG, Integer.toString(n)); if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){ BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "EUC-KR")); for(;;){ String line = br.readLine(); if(line == null) break; jsonHtml.append(line + "\n"); } Log.i(TAG, Integer.toString(3)); br.close(); } Log.i(TAG, Integer.toString(4)); conn.disconnect(); } } catch(Exception ex){ Log.i(TAG, ex.getMessage()); } Log.i(TAG, jsonHtml.toString()); Log.i(TAG, Integer.toString(5)); //I checked html string and number 5 showed up in log. return jsonHtml.toString(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload