Android Library Internet connection problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Android Library Internet connection problem

Postby Wubinator » Wed May 06, 2009 1:21 pm

Hi all,

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);"

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. protected String connect(ApiUrl url, Parameters parameters) {
  2.  
  3.                 String eveApiXML = "";
  4.  
  5.                 try {
  6.  
  7.                         HttpPost httpPost = new HttpPost();
  8.  
  9.  
  10.  
  11.                         UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(parameters
  12.  
  13.                                         .getParameters(), "ISO-8859-1");
  14.  
  15.  
  16.  
  17.                         httpPost.setEntity(p_entity);
  18.  
  19.  
  20.  
  21.                         /* Perform the actual HTTP POST */
  22.  
  23.                         DefaultHttpClient client = new DefaultHttpClient();
  24.  
  25.                         HttpResponse response = client.execute(httpPost);
  26.  
  27.                         HttpEntity entity = response.getEntity();
  28.  
  29.                         InputStream inStream = entity.getContent();
  30.  
  31.  
  32.  
  33.                         // Create the XML from the stream
  34.  
  35.                         eveApiXML = convertStreamToString(inStream);
  36.  
  37.  
  38.  
  39.                         // Check the XML for an error message
  40.  
  41.                 } catch (UnsupportedEncodingException uee) {
  42.  
  43.                         // Woops
  44.  
  45.                 } catch (IOException ioe) {
  46.  
  47.                         // Woops
  48.  
  49.                 } catch (IllegalStateException ise) {
  50.  
  51.                         // woops
  52.  
  53.                 }
  54.  
  55.  
  56.  
  57.                 return eveApiXML;
  58.  
  59.         }
Parsed in 0.034 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
Wubinator
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Apr 24, 2009 9:24 pm
Location: Amsterdam

Top

Postby padde » Wed May 06, 2009 5:04 pm

Check if p_entity contains the expected data..
it seams there is no or a wrong client set.


Greets
Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby Wubinator » Thu May 07, 2009 8:06 am

Ok this was a real "D'OH" moment ..... I forgot to provide the url to the HttpPost constructor.
Guess it was late yesterday ;)
Wubinator
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Apr 24, 2009 9:24 pm
Location: Amsterdam

Postby padde » Thu May 07, 2009 1:24 pm

:lol: :!:
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Google Feedfetcher and 5 guests