Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8232623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:53:42+00:00 2026-06-07T17:53:42+00:00

I want to use Jersey Client in my Android application. This is the code

  • 0

I want to use Jersey Client in my Android application.
This is the code for my client:

private JSONArray getJsonElements(){
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource service = client.resource(getBaseURI());
    JSONArray jarray = new JSONArray();
     jarray =  service.path("/collection").accept(MediaType.APPLICATION_JSON).get(JSONArray.class);
     Log.v(TAG, jarray.toString());
    return jarray;
}
private static URI getBaseURI() {
    return UriBuilder.fromUri("http://localhost:6577/Example/rest/Example")
            .build();
}

And here comes the problem.When i want to build application it gives me this very common exception:

java.lang.IllegalArgumentException: already added: Ljavax/ws/rs/core/GenericEntity;...2012-07-07 16:48:32 - SM] Conversion to Dalvik format failed with error 1

I saw all questions that were asked about this exception.It is possible to remove Jars from BuildPath and change choice of client(or I can create my client),but I don’t want to do this.
What can you recommend to me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:53:44+00:00Added an answer on June 7, 2026 at 5:53 pm

    Take a look in this link : http://www.vogella.com/articles/AndroidNetworking/article.html

    I myself prefer to use HTTP Client to connect the Android application to a Rest Service using Jersey since it supports the HTTP commands such as POST, PUT, DELETE, GET. For example to use GET command and trasferring data in JSON format:

    public class Client {
    
        private String server;
    
        public Client(String server) {
            this.server = server;
        }
    
        private String getBase() {
            return server;
        }
    
        public String getBaseURI(String str) {
            String result = "";
            try {
                HttpParams httpParameters = new BasicHttpParams();
                int timeoutConnection = 3000;
                HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
                int timeoutSocket = 5000;
                HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
                DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
                HttpGet getRequest = new HttpGet(getBase() + str);
                getRequest.addHeader("accept", "application/json");
                HttpResponse response = httpClient.execute(getRequest);
                result = getResult(response).toString();
                httpClient.getConnectionManager().shutdown();
            } catch (Exception e) {
                System.out.println(e.getMessage());
            } 
            return result;
        }
    
    
    
     private StringBuilder getResult(HttpResponse response) throws IllegalStateException, IOException {
                StringBuilder result = new StringBuilder();
                BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())), 1024);
                String output;
                while ((output = br.readLine()) != null) 
                    result.append(output);
    
                return result;      
          }
    }
    

    And then easily in another class you can:

    Client client = new Client("http://localhost:6577/Example/rest/");
    String str = client.getBaseURI("Example");    // Json format
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use this 1 for using Bar code or QR code scanner. I
We have a powerbuilder application and we want use a scanner through this application
I want to configure jersey client to use port 443 when connecting to a
I want use JQuery mobile for the front-end of my mobile application, but I
I don't want use old Visual Basic methods in my code, and I'm confused
I want use MVVM design pattern in WPF and Silverlight Application. Where can i
i want to use title on text. is this possible to make title on
I have class in server side and I want use method of this class
How can I use non-jersey resources with jersey resources with guice ? I want
I want use page that has this form: <form method=post action=modules.php?name=search> <input onkeypress=FKeyPress(this); onkeydown=FKeyDown(this);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.