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 7959649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:36:26+00:00 2026-06-04T04:36:26+00:00

I am trying to create a simple Android client for a web service I

  • 0

I am trying to create a simple Android client for a web service I have built, but something goes wrong at runtime.

Here is the Client:

public class MyClient extends AsyncTask<EditText, Integer, String> {

private EditText text;

protected String doInBackground(EditText... strings) {

    RuntimeDelegate
            .setInstance(new com.sun.ws.rs.ext.RuntimeDelegateImpl());
    WebResource wbr;
    Client client = Client.create();
    wbr = client
            .resource("http://my.ip:8080/MazeService/rest/service/hello");
    String result = wbr.queryParam("number", "10")
            .accept(MediaType.APPLICATION_JSON).get(String.class);
    text = strings[0];
    return result;
}

protected void onProgressUpdate(Integer... progress) {
    // setProgressPercent(progress[0]);
}

protected void onPostExecute(String result) {
    if (result != null)
        this.text.setText(result);
    else
        Log.d("MyApp", "No Result");
}

}

and the Service:

@Path("/service")
public class AndroidService {

@GET
@Produces(MediaType.APPLICATION_JSON )
@Path("/hello")
public String getJSON(@QueryParam("number") String nr)
{

    String s = "Hi there! The number is: "+nr;
    return s;
}
}

I get this stacktrace in LogCat:

02-18 16:26:06.446: E/AndroidRuntime(1381): FATAL EXCEPTION: AsyncTask #1
02-18 16:26:06.446: E/AndroidRuntime(1381): java.lang.RuntimeException: An error occured while executing doInBackground()
02-18 16:26:06.446: E/AndroidRuntime(1381):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at java.lang.Thread.run(Thread.java:856)
02-18 16:26:06.446: E/AndroidRuntime(1381): Caused by: java.lang.NullPointerException
02-18 16:26:06.446: E/AndroidRuntime(1381):     at javax.ws.rs.core.MediaType.valueOf(MediaType.java:119)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at com.sun.jersey.api.client.ClientResponse.getType(ClientResponse.java:615)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:532)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:506)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at com.sun.jersey.api.client.WebResource.handle(WebResource.java:674)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:503)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at com.maze.client.MyClient.doInBackground(MyClient.java:25)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at com.maze.client.MyClient.doInBackground(MyClient.java:1)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
02-18 16:26:06.446: E/AndroidRuntime(1381):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-18 16:26:06.446: E/AndroidRuntime(1381):     ... 5 more

I do not understand what the problem is, since a similar client works on PC. There is no problem with the IP address, since I can access the server from the Android VirtualDevice.

The Android version is 4.0.3 API version 15. For the client I used Jersey 1.11.

EDIT

I have also tried to remove the whole thing with the EditText, since someone told me it isn’t used as it should be. Still, I got the same error. I simply can not understand what am I doing wrong. If I should display any other additional information, please let me know. Also, ANY idea is good. I am new to Android and I might have made some stupid mistakes.

  • 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-04T04:36:27+00:00Added an answer on June 4, 2026 at 4:36 am

    Paul’s suggestion is correct. I got a little bit deeper in that subject and found a reason.

    Android apk packaging tool (APKBuilder class from sdklib.jar) ignores different folders while it creates the package (source). One of those folders is META-INF – no matter if its in the attached library or in the project’s source folder.

    Workaround for version 1.8 (and probably other also, but I didn’t test it) of Jersey is to provide custom (default one looks up META-INF/services/ which is not present in android apk) implementation for ServiceFinder$ServiceIteratorProvider which has hard coded provider class names. I based my implementation on this implementation proposed by Lucas:

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    
    import android.util.Log;
    
    import com.sun.jersey.spi.service.ServiceFinder.ServiceIteratorProvider;
    
    public class AndroidServiceIteratorProvider<T> extends ServiceIteratorProvider<T> {
    
        private static final String TAG = AndroidServiceIteratorProvider.class.getSimpleName();
        private static final String MESSAGE = "Unable to load provider";
    
        private static final HashMap<String, String[]> SERVICES = new HashMap<String, String[]>();
    
        private static final String[] com_sun_jersey_spi_HeaderDelegateProvider = {
                "com.sun.jersey.core.impl.provider.header.MediaTypeProvider",
                "com.sun.jersey.core.impl.provider.header.StringProvider"
        };
    
        private static final String[] com_sun_jersey_spi_inject_InjectableProvider = { 
        };
    
        private static final String[] javax_ws_rs_ext_MessageBodyReader = {
                "com.sun.jersey.core.impl.provider.entity.StringProvider",
                "com.sun.jersey.core.impl.provider.entity.ReaderProvider"
        };
    
        private static final String[] javax_ws_rs_ext_MessageBodyWriter = {
                "com.sun.jersey.core.impl.provider.entity.StringProvider",
                "com.sun.jersey.core.impl.provider.entity.ReaderProvider"
        };
    
        static {
            SERVICES.put("com.sun.jersey.spi.HeaderDelegateProvider",
                    com_sun_jersey_spi_HeaderDelegateProvider);
            SERVICES.put("com.sun.jersey.spi.inject.InjectableProvider",
                    com_sun_jersey_spi_inject_InjectableProvider);
            SERVICES.put("javax.ws.rs.ext.MessageBodyReader",
                    javax_ws_rs_ext_MessageBodyReader);
            SERVICES.put("javax.ws.rs.ext.MessageBodyWriter",
                    javax_ws_rs_ext_MessageBodyWriter);
            SERVICES.put("jersey-client-components", new String[]{});
            SERVICES.put("com.sun.jersey.client.proxy.ViewProxyProvider", new String[]{});
        }
    
        @SuppressWarnings("unchecked")
        @Override
        public Iterator<Class<T>> createClassIterator(Class<T> service,
                String serviceName, ClassLoader loader,
                boolean ignoreOnClassNotFound) {
    
            String[] classesNames = SERVICES.get(serviceName);
            int length = classesNames.length;
            ArrayList<Class<T>> classes = new ArrayList<Class<T>>(length);
            for (int i = 0; i < length; i++) {
                try {
                    classes.add((Class<T>) Class.forName(classesNames[i]));
                } catch (ClassNotFoundException e) {
                    Log.v(TAG, MESSAGE,e);
                }
            }
            return classes.iterator();
        }
    
        @Override
        public Iterator<T> createIterator(Class<T> service, String serviceName,
                ClassLoader loader, boolean ignoreOnClassNotFound) {
    
            String[] classesNames = SERVICES.get(serviceName);
            int length = classesNames.length;
            ArrayList<T> classes = new ArrayList<T>(length);
                for (int i = 0; i &lt; length; i++) {
                try {
                    classes.add(service.cast(Class.forName(classesNames[i])
                            .newInstance()));
                } catch (IllegalAccessException e) {
                    Log.v(TAG, MESSAGE,e);
                } catch (InstantiationException e) {
                    Log.v(TAG, MESSAGE,e);
                } catch (ClassNotFoundException e) {
                    Log.v(TAG, MESSAGE,e);
                }
            }
    
            return classes.iterator();
        }
    }
    

    I removed most of the classes since I didn’t use them and also they were causing verification errors on dalvik vm…

    NOTE: It means that with this implementation you can use only subset of headers/types supported by Jersey (I needed only String). To support other types you have to add providers located in META-INF/services folder of jersey-client.jar (or from Lucas’ implementation) and check if they don’t cause verification errors on Android.

    The above code should be used as follows:

    ServiceFinder.setIteratorProvider(new AndroidServiceIteratorProvider());
    Client client = Client.create();
    

    EDIT:

    It seems that the problem have been fixed in android-maven-plugin.

    mosa…@gmail.com wrote:

    The pull request with the fix was merged into master and will be released with 3.2.1:

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a simple android app in Java but I have
I am trying to create a simple android widget that shows The time but
I am trying to create a simple 3-D app for android that will have
I am trying to create a simple Android application that has a ActivityList of
I'm trying to create a simple app for android with progress bar . Everything
I'm studying webrat and cucumber and trying to create simple example. Here is my
Im trying to create a simple pan and zoom app using silverlight 4, but
Im trying to create a simple input box with form validation, but im not
Hi im trying to create a simple android app using the Eclipse IDE, all
I am trying to create a simple Icon+Text ListView but it does not work.

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.