I'm working on a API for an online game. This API must connect to a internet page, retrieve a XML and parse the XML to usable objects.
I've created a new Java project for this and added the Android.jar as library of this project. Now when I test the functionality of this API it fails on the part where the Internet connection is made.
Below is the method that handles the connection and the error is made on the line "HttpResponse response = client.execute(httpPost);"
Using java Syntax Highlighting
- protected String connect(ApiUrl url, Parameters parameters) {
- String eveApiXML = "";
- try {
- HttpPost httpPost = new HttpPost();
- UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(parameters
- .getParameters(), "ISO-8859-1");
- httpPost.setEntity(p_entity);
- /* Perform the actual HTTP POST */
- DefaultHttpClient client = new DefaultHttpClient();
- HttpResponse response = client.execute(httpPost);
- HttpEntity entity = response.getEntity();
- InputStream inStream = entity.getContent();
- // Create the XML from the stream
- eveApiXML = convertStreamToString(inStream);
- // Check the XML for an error message
- } catch (UnsupportedEncodingException uee) {
- // Woops
- } catch (IOException ioe) {
- // Woops
- } catch (IllegalStateException ise) {
- // woops
- }
- return eveApiXML;
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
It looks like a NullPointerException:
05-06 14:15:22.711: ERROR/AndroidRuntime(1210): Uncaught handler: thread main exiting due to uncaught exception
05-06 14:15:22.800: ERROR/AndroidRuntime(1210): java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.wubinator.tester/nl.wubinator.tester.characters.CharactersTester}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2141)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2157)
at android.app.ActivityThread.access$1800(ActivityThread.java:112)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1581)
at android.os.Handler.dispatchMessage(Handler.java:88)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3739)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:496)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at nl.wubinator.aeve.connectors.ConnectorBase.connect(ConnectorBase.java:41)
at nl.wubinator.aeve.connectors.LimitedConnector.getCharacters(LimitedConnector.java:23)
at nl.wubinator.tester.characters.CharactersTester.onCreate(CharactersTester.java:20)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2104)
... 11 more
I test this from an Android application.
I have enabled Internet persimission in the AndroidManifest.xml of this application.
I cannot find out how to solve this problem ... any idea?
Cheers,
Rick



