Announcement Announcement Module
Collapse
No announcement yet.
Can't find HttpClient? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't find HttpClient?

    I am trying to use the latest Spring for Android 1.0.1 with a simple get:
    Code:
    RestTemplate restTemplate = new RestTemplate();
    	    restTemplate.setRequestFactory(new CommonsClientHttpRequestFactory());
    	    String url = "http://localhost:8090//rest/all";
    	    Mine m = restTemplate(getForObject(url, Mine.class);
    This results in a crash:
    Code:
    03-06 11:17:07.490: E/AndroidRuntime(544): FATAL EXCEPTION: main
    03-06 11:17:07.490: E/AndroidRuntime(544): java.lang.NoClassDefFoundError: org.apache.commons.httpclient.HttpClient
    03-06 11:17:07.490: E/AndroidRuntime(544): 	at org.springframework.http.client.CommonsClientHttpRequestFactory.<init>(CommonsClientHttpRequestFactory.java:63)
    Since it says HttpClient is missing, I downloaded httpcomponents-client-4.2.3 and added the seven jars to my project. I still get the same error.

    How do I get past this HttpClient error?

  • #2
    Hi, httpcomponents-client-4.2.3 is not compatible with RestTemplate in Spring for Android. The CommonsClientHttpRequestFactory is for use with the Commons HttpClient 3.1. Support for this is deprecated in Spring for Android, in favor of one of the native Android HTTP clients.

    Spring for Android automatically uses the SimpleClientHttpRequestFactory (Gingerbread and newer) unless you specify a different factory as you are doing. I recommend trying to use RestTemplate without specifying one, unless you have a reason to.

    Comment


    • #3
      Hey, I don't have any information about this forum so I am unable to make any comment. I think that I have to do more homework in learning things.

      Comment

      Working...
      X