我正在开发一些应用程序,我想将它们连接到Restful WebService。要做到这一点,我写这个类:在Android中访问ResTWebService
public class TagDS {
public TagDS(){
}
public boolean recordTag(Tag t){
try{
String send = t.getConteudo()+"\n"+t.getId()+"\n"+t.getURL()+"\n"+t.getData()+"\n"+t.getUser();
postService(send);
return true;
}catch(Exception e){
return false;
}
}
public void postService(String send) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
service.path("rest").path("project").path("create").path(send).accept(MediaType.TEXT_PLAIN).post();
}
private static URI getBaseURI() {
return UriBuilder.fromUri(
"http://localhost:8080/pt.Android.Project.WebService").build();
}
}
但是当我运行应用程序时,将显示menssage:
<p>08-16 10:24:33.280: E/AndroidRuntime(24149): FATAL EXCEPTION: main </p>
<p>08-16 10:24:33.280: E/AndroidRuntime(24149): java.lang.NoClassDefFoundError: com.sun.jersey.api.client.config.DefaultClientConfig</p>
我已经添加到项目中的所有库。我的问题是:当我们创建一个apk时,有没有可能库没有加载?
我已经单独测试了我的WebService并且它可以正常工作。我认为“马比问题是Android权限”,但我搜查了,我有权限:
<user-permission android:name="android.permission.INTERNET" />
你能帮我吗?
真诚, 丽塔
您是否将所需的jar添加到项目的lib文件夹中? – FWeigl 2012-08-16 13:07:57
是的,我做到了! :S – Rita 2012-08-16 13:12:10