gpt4 book ai didi

java - Android ReSTLet 包裹崩溃

转载 作者:行者123 更新时间:2023-12-01 15:51:22 29 4
gpt4 key购买 nike

我使用的是 Android 1.6 和 ReSTLet android 版本 2.0.7...

它在wrap()上崩溃:

ClientResource cr = new ClientResource("http://myapp.appspot.com/restlet/");
IRestletResource r = cr.wrap(IRestletResource.class);
MyData[] ss = r.getDatas();

这么说

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.getFullListOfMethods(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)
...

界面看起来像

public interface IRestletResource 
{
@Get
public MyData[] getDatas();
}

服务器端 ReSTLetResource 如下所示:

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 看起来像这样:

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;
}
//...
}
现在。如果我更改资源以返回字符串而不是 MyData[],它不会崩溃。如果我返回一个 MyData 实例而不是一个数组,它仍然会崩溃。

最佳答案

原来你需要

Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());

在客户端,以及

getConnectorService().getClientProtocols().add(Protocol.FILE);

在服务器端的应用程序中..

关于java - Android ReSTLet 包裹崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5960325/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com