Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.NullPointerException in my AsyncTask
    text
    copied!<p>I am getting an NPE in this code, I need a fix very quickly, can someone give me a hand?</p> <pre><code>import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import android.os.AsyncTask; public class GetXML extends AsyncTask&lt;String, String, BirdData&gt; { public GetXML(){ } /** * background */ @Override protected BirdData doInBackground(String... params) { String GetWikiID = params[0]; // All static variables String URL = "http://www.bbc.co.uk/nature/life/"+GetWikiID+".rdf"; // XML node keys XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL); // getting XML Document doc = parser.getDomElement(xml); // getting DOM element System.out.println("test3"); System.out.println(doc.getElementById("dc:description").getTextContent()); return null; } /** * on getting result */ @Override protected void onPostExecute(BirdData result) { } } </code></pre> <p>I am using this code to call it:</p> <pre><code>System.out.println(WikiID); new GetXML().execute(WikiID); </code></pre> <p>and the error is this: </p> <pre><code> 08-08 16:04:17.284: E/AndroidRuntime(17971): FATAL EXCEPTION: AsyncTask #1 08-08 16:04:17.284: E/AndroidRuntime(17971): java.lang.RuntimeException: An error occured while executing doInBackground() 08-08 16:04:17.284: E/AndroidRuntime(17971): at android.os.AsyncTask$3.done(AsyncTask.java:299) 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 08-08 16:04:17.284: E/AndroidRuntime(17971): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.lang.Thread.run(Thread.java:856) 08-08 16:04:17.284: E/AndroidRuntime(17971): Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 45: http://www.bbc.co.uk/nature/tools/search/Type text here... 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.net.URI.create(URI.java:727) 08-08 16:04:17.284: E/AndroidRuntime(17971): at org.apache.http.client.methods.HttpPost.&lt;init&gt;(HttpPost.java:79) 08-08 16:04:17.284: E/AndroidRuntime(17971): at com.swift.birdspot.JSONParser.getJSONFromUrl(JSONParser.java:36) 08-08 16:04:17.284: E/AndroidRuntime(17971): at com.swift.birdspot.GetWikiID.doInBackground(GetWikiID.java:31) 08-08 16:04:17.284: E/AndroidRuntime(17971): at com.swift.birdspot.GetWikiID.doInBackground(GetWikiID.java:1) 08-08 16:04:17.284: E/AndroidRuntime(17971): at android.os.AsyncTask$2.call(AsyncTask.java:287) 08-08 16:04:17.284: E/AndroidRuntime(17971): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 08-08 16:04:17.284: E/AndroidRuntime(17971): ... 5 more </code></pre>
 

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