My code is:
Client client = Client.create();
WebResource web_resource = client.resource("http://www.myhostname.com/");
// String string = web_resource.path("foo").accept("text/xml").get(String.class);
// Log.d(getClass().getCanonicalName(), "jax-rs client string = " + string);
Num num = web_resource.path("foo").accept(MediaType.TEXT_XML_TYPE).get(Num.class);
The last line causes the problem, and I get a similar problem if I replace it with the 2 commented lines with the difference that I get the exception on a different line of MediaType.java.
E/AndroidRuntime( 840): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 840): at javax.ws.rs.core.MediaType.toString(MediaType.java:265)
E/AndroidRuntime( 840): at com.sun.jersey.api.client.ClientRequest.getHeaderValue(ClientRequest.java:232)
E/AndroidRuntime( 840): at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.writeOutBoundHeaders(URLConnectionClientHandler.java:276)
E/AndroidRuntime( 840): at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:197)
E/AndroidRuntime( 840): at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
E/AndroidRuntime( 840): ... 17 more
jersey-client.jar and jersey-core.jar have been added to the package at the top level and have been added to libraries in build path.
AndroidManifest.xml contains:
<uses-permission android:name="android.permission.INTERNET" />
This was a huge exercise. I believe I might be the only person yet who has gotten Jersey+JAXB working on Android. A specific answer won’t help because after I got around this NullPointerException I got another exception, and then another.
I had to change source code for Jersey and JAXB in order to make this happen. And I also had to repackage the jars.
Sorry I know this is a bad quality answer but please comment me if somebody really wants to go down this difficult path in which case I can retrace my steps and help out.