0

I am getting an NPE in this code, I need a fix very quickly, can someone give me a hand?

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<String, String, BirdData> {

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) {

}
}

I am using this code to call it:

System.out.println(WikiID);
new GetXML().execute(WikiID);

and the error is this:

    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.<init>(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
18
  • 4
    If you're in a hurry then it would speed things along if you posted the logcat Commented Aug 8, 2013 at 15:02
  • 1
    Do you have the permissions to use INTERNET in the AndroidManifest? Commented Aug 8, 2013 at 15:03
  • 2
    Based on your edit: IllegalArgumentException != NullPointerException. You use an invalid URL character in WikiID. Commented Aug 8, 2013 at 15:06
  • 2
    Its not NPE its IllegalArgumentException check your URL Commented Aug 8, 2013 at 15:07
  • 3
    @SwiftAppDesign check the log: Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 45: http://www.bbc.co.uk/nature/tools/search/Type text here... Commented Aug 8, 2013 at 15:13

2 Answers 2

1

The error is that there are invalid characters (space characters) on the following URL:

http://www.bbc.co.uk/nature/tools/search/Type text here...

You should fix this URL and your problem will be solved!

Sign up to request clarification or add additional context in comments.

Comments

0

Turns out all I needed to do was url encode inside my jsonparser class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.