Hi,
I am trying to write a RESTful client for Android platform using
Jersey API. I am using ADT for Eclipse. Below is the source code
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class AndroidJerceyClientActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)
findViewById(R.id.outputTextView);
try {
RESTfulClientImplementation restClient = new
RESTfulClientImplementation();
String response = restClient.doGet();
textView.setText(response);
} catch (Exception e) {
textView.setText(e.getMessage());
}
}
}
public class RESTfulClientImplementation {
private ClientConfig configLight;
private Client client;
public RESTfulClientImplementation() {
configLight = new DefaultClientConfig();
client = Client.create(configLight);
}
public String doGet() {
try {
WebResource service = client.resource(new URI(
"http://smartbridge.homeip.net"));
String response =
service.path("api").path("00178800ffd9")
.path("messagequeue").path("2")
.accept(MediaType.APPLICATION_JSON).get(String.class);
System.out.println("Complete Response Jercey API: " +
response);
return response;
} catch (Exception e) {
}
return null;
}
}
If I try to deploy this application I am getting an exception. Below
is the trace from LogCat
10-11 09:56:21.854: WARN/dalvikvm(474): threadid=1: thread exiting
with uncaught exception (group=0x4001d800)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): FATAL EXCEPTION: main
10-11 09:56:22.123: ERROR/AndroidRuntime(474):
java.lang.ExceptionInInitializerError
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.sun.jersey.core.spi.factory.MessageBodyFactory._getMessageBodyReader(MessageBodyFactory.java:
311)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.sun.jersey.core.spi.factory.MessageBodyFactory.getMessageBodyReader(MessageBodyFactory.java:
298)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:
536)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:
506)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.sun.jersey.api.client.WebResource.handle(WebResource.java:674)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:
503)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
org.philips.jerceyclient.RESTfulClientImplementation.doGet(RESTfulClientImplementation.java:
42)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
org.philips.jerceyclient.AndroidJerceyClientActivity.onCreate(AndroidJerceyClientActivity.java:
17)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2627)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2679)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
android.os.Handler.dispatchMessage(Handler.java:99)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
android.os.Looper.loop(Looper.java:123)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
android.app.ActivityThread.main(ActivityThread.java:4627)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
java.lang.reflect.Method.invokeNative(Native Method)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
java.lang.reflect.Method.invoke(Method.java:521)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
dalvik.system.NativeStart.main(Native Method)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): Caused by:
java.lang.NullPointerException
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
javax.ws.rs.core.MediaType.valueOf(MediaType.java:119)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): at
com.sun.jersey.core.header.MediaTypes.<clinit>(MediaTypes.java:64)
10-11 09:56:22.123: ERROR/AndroidRuntime(474): ... 22 more
I have added jersey-client-1.9.1.jar and jersey-core-1.9.1.jar in the
project classpath.
I appreciate if someone help me to solve this problem.
Best regards
Yeasin Habib
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en