Android Restlet Wrap Crashing
I am using Android 1.6 and restlet android edition 2.0.7...
It crashes on wrap():
ClientResource cr = new ClientResource("http://myapp.appspot.com/restlet/");
IRestletResource r = cr.wrap(IRestletResource.class);
MyData[] ss = r.getDatas();
saying that
05-10 20:40:56.272: ERROR/AndroidRuntime(435): java.lang.RuntimeException: Unable to start activity ComponentInfo{se.myapp.android/se.myapp.android.MyAppAndroid}: java.lang.NoSuchMethodException
...
05-10 20:40:56.272: ERROR/AndroidRuntime(435): Caused by: java.lang.NoSuchMethodException
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at java.lang.Class.getDeclaredMethods(Native Method)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at java.lang.ClassCache.getDeclaredPublicMethods(ClassCache.java:166)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at java.lang.ClassCache.getDeclaredMethods(ClassCache.java:179)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at java.lang.ClassCache.findAllMethods(ClassCache.java:249)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at java.lang.ClassCache.getFullLis开发者_Python百科tOfMethods(ClassCache.java:223)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at java.lang.ClassCache.getAllPublicMethods(ClassCache.java:204)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at java.lang.Class.getMethods(Class.java:1038)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at org.restlet.engine.resource.AnnotationUtils.addAnnotations(AnnotationUtils.java:131)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at org.restlet.engine.resource.AnnotationUtils.getAnnotations(AnnotationUtils.java:231)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at org.restlet.resource.ClientResource.wrap(ClientResource.java:1541)
05-10 20:40:56.272: ERROR/AndroidRuntime(435): at se.myapp.android.MyAppAndroid.onCreate(MyAppAndroid.java:61)
...
Interface looks like
public interface IRestletResource
{
@Get
public MyData[] getDatas();
}
Serverside RestletResource looks like this:
public class RestletResource extends ServerResource implements IRestletResource
{
MyData[] m_Datas;
@Override
protected void doInit() throws ResourceException
{
m_Datas = new MyData("carl",32);
}
@Get
public MyData[] getDatas()
{
return m_Datas; //return new myData("..",1); still crashes.
}
}
MyData looks like this:
public class MyData implements Serializable
{
private static final long serialVersionUID = 1L;
private String m_Name;
private int m_Age;
public MyData()
{
}
public MyData(String n, int a)
{
m_Name = n;
m_Age = a;
}
//...
}
Now. It does NOT crash if i change the resource to return a String instead of MyData[]. It does still crash if i return one instance of MyData instead of an array.
Turns out you need
Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
on the client side, aswell as
getConnectorService().getClientProtocols().add(Protocol.FILE);
in your Application on the server side..
精彩评论