Note that there are some explanatory texts on larger screens.

plurals
  1. PONetworkOnMainThread exception android. fetching server response
    primarykey
    data
    text
    <p>I am getting the exception android.os.NetworkOnMainThreadException when I tried to use the following codes:</p> <pre><code>public class CheckServer extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); Runnable runn = null; HttpTask.execute(runn); } private class HttpTask extends AsyncTask&lt;String, String, String&gt; { @Override protected String doInBackground(String... params) { // TODO Auto-generated method stub HttpURLConnection urlConnection = null; URL theURL = null; try { theURL = new URL("http://192.168.2.8/parkme/Client/clientquery.php?ticket=66t"); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { urlConnection = (HttpURLConnection) theURL.openConnection(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String response = null; try { response = readInputStream(urlConnection.getInputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return response; } private String readInputStream(InputStream is) { // TODO Auto-generated method stub String line = ""; StringBuilder total = new StringBuilder(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); try { while ((line = rd.readLine()) != null) { total.append(line); } } catch (Exception e) { e.printStackTrace(); } return total.toString(); } @Override protected void onPostExecute(String result) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show(); } }} </code></pre> <p>If possible can someone tell me how to use it inside an Async Task and get the output? I tried but can't seem to get anywhere.</p>
    singulars
    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