Note that there are some explanatory texts on larger screens.

plurals
  1. PONull pointer Exception on Parsing URL in android
    primarykey
    data
    text
    <p>Here Im trying to parsing read from url and trying to print in console.Im using Asynctask as we cant have network connection on main thread</p> <pre><code>package com.example.parse; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import android.os.AsyncTask; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button create =(Button) findViewById(R.id.button1); create.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click EditText et1 = (EditText) findViewById(R.id.editText1); String url = et1.getText().toString(); new ParseString().execute(url); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } </code></pre> <p>}</p> <pre><code> class ParseString extends AsyncTask&lt;String, Void, BufferedReader&gt;{ @Override protected BufferedReader doInBackground(String... urls) { // TODO Auto-generated method stub BufferedReader in = null; URL url = null; try { url = new URL(urls[0]); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { in = new BufferedReader( new InputStreamReader( url.openStream())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return in; } protected void onPostExecute(BufferedReader buf){ String inputLine; try { while ((inputLine = buf.readLine()) != null) System.out.println(inputLine); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { buf.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p>This is the log cat error message</p> <pre><code>12-13 01:33:58.404: E/AndroidRuntime(1058): FATAL EXCEPTION: AsyncTask #2 12-13 01:33:58.404: E/AndroidRuntime(1058): Process: com.example.parse, PID: 1058 12-13 01:33:58.404: E/AndroidRuntime(1058): java.lang.RuntimeException: An error occured while executing doInBackground() 12-13 01:33:58.404: E/AndroidRuntime(1058): at android.os.AsyncTask$3.done(AsyncTask.java:300) 12-13 01:33:58.404: E/AndroidRuntime(1058): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) 12-13 01:33:58.404: E/AndroidRuntime(1058): at java.util.concurrent.FutureTask.setException(FutureTask.java:222) 12-13 01:33:58.404: E/AndroidRuntime(1058): at java.util.concurrent.FutureTask.run(FutureTask.java:242) 12-13 01:33:58.404: E/AndroidRuntime(1058): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 12-13 01:33:58.404: E/AndroidRuntime(1058): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 12-13 01:33:58.404: E/AndroidRuntime(1058): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 12-13 01:33:58.404: E/AndroidRuntime(1058): at java.lang.Thread.run(Thread.java:841) 12-13 01:33:58.404: E/AndroidRuntime(1058): Caused by: java.lang.NullPointerException 12-13 01:33:58.404: E/AndroidRuntime(1058): at com.example.parse.ParseString.doInBackground(MainActivity.java:62) 12-13 01:33:58.404: E/AndroidRuntime(1058): at com.example.parse.ParseString.doInBackground(MainActivity.java:1) 12-13 01:33:58.404: E/AndroidRuntime(1058): at android.os.AsyncTask$2.call(AsyncTask.java:288) 12-13 01:33:58.404: E/AndroidRuntime(1058): at java.util.concurrent.FutureTask.run(FutureTask.java:237) 12-13 01:33:58.404: E/AndroidRuntime(1058): ... 4 more </code></pre> <p>P.S I have added network permission in manifest.xml </p>
    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.
    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