Getting NullPointException with Jersey REST Client on Android

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 two commented lines with the difference that I get an exception in another 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 are added to the package at the top level and added to libraries in the build path.

AndroidManifest.xml contains:

  <uses-permission android:name="android.permission.INTERNET" /> 
+6
source share
2 answers

It was a huge exercise. I believe that I may be the only person who has Jersey + JAXB running on Android. The specific answer won't help, because after I got around this NullPointerException, I got one more exception and then another.

I had to change the source code for Jersey and JAXB to make this happen. And I also had to repack the banks.

Sorry, I know this is a bad answer, but please comment to me if someone really wants to go along this difficult path, in which case I can repeat the steps and help.

+3
source

I had the same problem with a T-shirt. I switched to Google Gson and everything worked out fine.

+1
source

Source: https://habr.com/ru/post/904194/


All Articles