gpt4 book ai didi

java - Android 支持 Jersey 客户端吗?

转载 作者:太空狗 更新时间:2023-10-29 15:00:58 27 4
gpt4 key购买 nike

我想使用 REST Jersey Client 来调用网络服务。但是从android应用程序调用时它失败了;当从简单的 Java 客户端(没有任何 Android 代码)调用时,相同的 Web 服务调用有效。这是否意味着 Jersey Client 在 Android 上下文中调用时不起作用,或者它需要任何特定配置才能进行 REST 调用?

我的 pom.xml 有这个:

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.13</version>
</dependency>

我的示例代码:

  Response getResponse = ClientBuilder.newClient()
.target("http://myserver:8081").path("/users/employees")
.request()
.get();

我在 android 模拟器日志中看到这些错误:

Failed resolving Lorg/glassfish/jersey/internal/OsgiRegistry; interface 2690 'Lorg/osgi/framework/SynchronousBundleListener;'
Link of class 'Lorg/glassfish/jersey/internal/OsgiRegistry;' failed
VFY: unable to find class referenced in signature (Lorg/glassfish/jersey/internal/OsgiRegistry;)
...
Cannot find default implementation of the HK2 ServiceLocatorGenerator
java.lang.ClassNotFoundException: Provider of org.glassfish.jersey.internal.RuntimeDelegateImpl could not be instantiated: java.lang.IllegalStateException: No generator was provided and there is no default generator registered.

相关评论here :“Android 有 Dalvik 虚拟机,而不是原始的 JVM。我认为这就是 Jersey Client API 在 Android 操作系统中不起作用的原因。但我很确定!”

最佳答案

这篇文章是相关的:

When using Jersey for restful api in Android app I get this error:

似乎 android 不支持 Jersey 客户端:我尝试在 android 中为 REST api 程序导入一个工作的 jersey 客户端,但出现致命异常。

12-16 16:41:33.049    3711-3711/com.program.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.program.example, PID: 3711
java.lang.VerifyError: com/sun/jersey/core/impl/provider/entity/MimeMultipartProvider
at java.lang.Class.getDeclaredConstructors(Native Method)
at java.lang.Class.getConstructors(Class.java:508)
at com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(ComponentConstructor.java:174)
at com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java:166)
at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:137)
at com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:256)
at com.sun.jersey.core.spi.component.ProviderServices.getServices(ProviderServices.java:160)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:176)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)
at com.sun.jersey.api.client.Client.init(Client.java:342)
at com.sun.jersey.api.client.Client.access$000(Client.java:118)
at com.sun.jersey.api.client.Client$1.f(Client.java:191)
at com.sun.jersey.api.client.Client$1.f(Client.java:187)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.api.client.Client.<init>(Client.java:187)
at com.sun.jersey.api.client.Client.<init>(Client.java:159)
at com.sun.jersey.api.client.Client.create(Client.java:669)
at android.view.View.performClick(View.java)
at android.view.View$PerformClick.run(View.java)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)

我希望我能发表评论...

关于java - Android 支持 Jersey 客户端吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26873448/

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