0

嘿,我正在开发一个 android 应用程序,我遇到了一个问题,我想为我的 android 应用程序开发一个 web http 服务器,通过我的研究,我遇到了这个例子

在您的应用程序中集成 Jetty 服务器

每当我尝试运行它时,我都会遇到这种我不知道如何解决的错误,有没有人遇到过这个错误或类似的错误?我正在使用 eclipse 并尝试在 android 4.2.2 和 4.1.2 上运行它

05-23 12:53:18.351: D/dalvikvm(626): Not late-enabling CheckJNI (already on) 05-23 12:53:19.112: E/Trace(626): error opening trace file: No such file or directory (2) 05-23 12:53:19.461: W/dalvikvm(626): Unable to resolve superclass of Lcom/example/jettytest/MainActivity$1; (641) 05-23 12:53:19.461: W/dalvikvm(626): Link of class 'Lcom/example/jettytest/MainActivity$1;' failed 05-23 12:53:19.461: E/dalvikvm(626): Could not find class 'com.example.jettytest.MainActivity$1', referenced from method com.example.jettytest.MainActivity.<init> 05-23 12:53:19.461: W/dalvikvm(626): VFY: unable to resolve new-instance 536 (Lcom/example/jettytest/MainActivity$1;) in Lcom/example/jettytest/MainActivity; 05-23 12:53:19.461: D/dalvikvm(626): VFY: replacing opcode 0x22 at 0x0003 05-23 12:53:19.471: E/dalvikvm(626): Could not find class 'org.eclipse.jetty.server.Server', referenced from method com.example.jettytest.MainActivity.onCreate 05-23 12:53:19.471: W/dalvikvm(626): VFY: unable to resolve new-instance 640 (Lorg/eclipse/jetty/server/Server;) in Lcom/example/jettytest/MainActivity; 05-23 12:53:19.471: D/dalvikvm(626): VFY: replacing opcode 0x22 at 0x0008 05-23 12:53:19.471: W/dalvikvm(626): Unable to resolve superclass of Lcom/example/jettytest/MainActivity$1; (641) 05-23 12:53:19.471: W/dalvikvm(626): Link of class 'Lcom/example/jettytest/MainActivity$1;' failed 05-23 12:53:19.471: D/dalvikvm(626): DexOpt: unable to opt direct call 0x0ff3 at 0x05 in Lcom/example/jettytest/MainActivity;.<init> 05-23 12:53:19.471: D/dalvikvm(626): DexOpt: unable to opt direct call 0x10bf at 0x0c in Lcom/example/jettytest/MainActivity;.onCreate 05-23 12:53:19.481: D/AndroidRuntime(626): Shutting down VM 05-23 12:53:19.481: W/dalvikvm(626): threadid=1: thread exiting with uncaught exception (group=0x40a13300) 05-23 12:53:19.491: E/AndroidRuntime(626): FATAL EXCEPTION: main 05-23 12:53:19.491: E/AndroidRuntime(626): java.lang.NoClassDefFoundError: com.example.jettytest.MainActivity$1 05-23 12:53:19.491: E/AndroidRuntime(626): at com.example.jettytest.MainActivity.<init>(MainActivity.java:26) 05-23 12:53:19.491: E/AndroidRuntime(626): at java.lang.Class.newInstanceImpl(Native Method) 05-23 12:53:19.491: E/AndroidRuntime(626): at java.lang.Class.newInstance(Class.java:1319) 05-23 12:53:19.491: E/AndroidRuntime(626): at android.app.Instrumentation.newActivity(Instrumentation.java:1053) 05-23 12:53:19.491: E/AndroidRuntime(626): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974) 05-23 12:53:19.491: E/AndroidRuntime(626): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 05-23 12:53:19.491: E/AndroidRuntime(626): at android.app.ActivityThread.access$600(ActivityThread.java:130) 05-23 12:53:19.491: E/AndroidRuntime(626): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 05-23 12:53:19.491: E/AndroidRuntime(626): at android.os.Handler.dispatchMessage(Handler.java:99) 05-23 12:53:19.491: E/AndroidRuntime(626): at android.os.Looper.loop(Looper.java:137) 05-23 12:53:19.491: E/AndroidRuntime(626): at android.app.ActivityThread.main(ActivityThread.java:4745) 05-23 12:53:19.491: E/AndroidRuntime(626): at java.lang.reflect.Method.invokeNative(Native Method) 05-23 12:53:19.491: E/AndroidRuntime(626): at java.lang.reflect.Method.invoke(Method.java:511) 05-23 12:53:19.491: E/AndroidRuntime(626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 05-23 12:53:19.491: E/AndroidRuntime(626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 05-23 12:53:19.491: E/AndroidRuntime(626): at dalvik.system.NativeStart.main(Native Method) 05-23 12:53:21.291: I/Process(626): Sending signal. PID: 626 SIG: 9

4

1 回答 1

1

对于初学者,请使用 Jetty 7,因为它与 Android 使用的 JDK 兼容。

(Jetty 8 使用了 Android 中不存在的 JDK 6 的高级功能,而 Jetty 9 对 JDK 7 的最低要求对 Android 来说太新了)

您收到的错误Could not find class 'org.eclipse.jetty.server.Server'通常表明您尝试将 Jetty 8/9 与 Android 一起使用(或者更罕见的是,您遇到了打包错误)

您还必须将 Jetty 使用的标准 JVM 类加载器替换为与 Android 兼容的类加载器。

Android 上 Jetty 7 的开源示例可以在位于code.google.com/p/i-jetty/的 i-jetty 项目中找到。i-jetty 项目由 Jetty 开发人员维护。

于 2013-05-23T13:07:10.707 回答