将一个外部的库(JAR),放到工程的lib下,编译成功,运行时,总报如下的错:
08-05 02:58:27.661: W/dalvikvm(977): VFY: unable to resolve static field 87 (D8) in Ltw/com/prolific/driver/pl2303/PL2303Driver$DataBits;
08-05 02:58:27.661: D/dalvikvm(977): VFY: replacing opcode 0x62 at 0x0007
08-05 02:58:27.701: I/dalvikvm(977): Could not find method tw.com.prolific.driver.pl2303.PL2303Driver.isConnected, referenced from method com.prolific.pl2303hxdsimpletest.PL2303HXDSimpleTest.openUsbSerial
08-05 02:58:27.701: W/dalvikvm(977): VFY: unable to resolve virtual method 131: Ltw/com/prolific/driver/pl2303/PL2303Driver;.isConnected ()Z
08-05 02:58:27.701: D/dalvikvm(977): VFY: replacing opcode 0x6e at 0x000f
08-05 02:58:27.751: I/dalvikvm(977): Could not find method tw.com.prolific.driver.pl2303.PL2303Driver.isConnected, referenced from method com.prolific.pl2303hxdsimpletest.PL2303HXDSimpleTest.readDataFromSerial
08-05 02:58:27.751: W/dalvikvm(977): VFY: unable to resolve virtual method 131: Ltw/com/prolific/driver/pl2303/PL2303Driver;.isConnected ()Z
08-05 02:58:27.751: D/dalvikvm(977): VFY: replacing opcode 0x6e at 0x0017
08-05 02:58:27.751: I/dalvikvm(977): Could not find method tw.com.prolific.driver.pl2303.PL2303Driver.isConnected, referenced from method com.prolific.pl2303hxdsimpletest.PL2303HXDSimpleTest.writeDataToSerial
08-05 02:58:27.751: W/dalvikvm(977): VFY: unable to resolve virtual method 131: Ltw/com/prolific/driver/pl2303/PL2303Driver;.isConnected ()Z
08-05 02:58:27.751: D/dalvikvm(977): VFY: replacing opcode 0x6e at 0x000e
08-05 02:58:27.801: I/dalvikvm(977): Could not find method tw.com.prolific.driver.pl2303.PL2303Driver.isConnected, referenced from method com.prolific.pl2303hxdsimpletest.PL2303HXDSimpleTest.SetNewVIDPID
08-05 02:58:27.801: W/dalvikvm(977): VFY: unable to resolve virtual method 131: Ltw/com/prolific/driver/pl2303/PL2303Driver;.isConnected ()Z
08-05 02:58:27.831: D/dalvikvm(977): VFY: replacing opcode 0x6e at 0x0027
08-05 02:58:27.831: E/dalvikvm(977): Could not find class 'tw.com.prolific.driver.pl2303.PL2303Driver', referenced from method com.prolific.pl2303hxdsimpletest.PL2303HXDSimpleTest.onCreate
08-05 02:58:27.881: I/dalvikvm(977): threadid=3: reacting to signal 3
08-05 02:58:27.881: W/dalvikvm(977): VFY: unable to resolve new-instance 77 (Ltw/com/prolific/driver/pl2303/PL2303Driver;) in Lcom/prolific/pl2303hxdsimpletest/PL2303HXDSimpleTest;
08-05 02:58:27.881: D/dalvikvm(977): VFY: replacing opcode 0x22 at 0x009d
08-05 02:58:27.921: I/dalvikvm(977): Wrote stack traces to '/data/anr/traces.txt'
08-05 02:58:27.941: I/dalvikvm(977): Could not find method tw.com.prolific.driver.pl2303.PL2303Driver.end, referenced from method com.prolific.pl2303hxdsimpletest.PL2303HXDSimpleTest.onDestroy
08-05 02:58:27.941: W/dalvikvm(977): VFY: unable to resolve virtual method 129: Ltw/com/prolific/driver/pl2303/PL2303Driver;.end ()V
08-05 02:58:27.941: D/dalvikvm(977): VFY: replacing opcode 0x6e at 0x000d
08-05 02:58:27.951: I/dalvikvm(977): Could not find method tw.com.prolific.driver.pl2303.PL2303Driver.isConnected, referenced from method com.prolific.pl2303hxdsimpletest.PL2303HXDSimpleTest.onResume
08-05 02:58:27.951: W/dalvikvm(977): VFY: unable to resolve virtual method 131: Ltw/com/prolific/driver/pl2303/PL2303Driver;.isConnected ()Z
08-05 02:58:27.991: D/dalvikvm(977): VFY: replacing opcode 0x6e at 0x0029
08-05 02:58:27.991: D/dalvikvm(977): DexOpt: unable to opt direct call 0x007e at 0xa9 in Lcom/prolific/pl2303hxdsimpletest/PL2303HXDSimpleTest;.onCreate
08-05 02:58:27.991: D/AndroidRuntime(977): Shutting down VM
08-05 02:58:28.001: W/dalvikvm(977): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-05 02:58:28.001: E/AndroidRuntime(977): FATAL EXCEPTION: main
08-05 02:58:28.001: E/AndroidRuntime(977): java.lang.NoClassDefFoundError: tw.com.prolific.driver.pl2303.PL2303Driver$DataBits
08-05 02:58:28.001: E/AndroidRuntime(977): at com.prolific.pl2303hxdsimpletest.PL2303HXDSimpleTest.<init>(PL2303HXDSimpleTest.java:71)
08-05 02:58:28.001: E/AndroidRuntime(977): at java.lang.Class.newInstanceImpl(Native Method)
08-05 02:58:28.001: E/AndroidRuntime(977): at java.lang.Class.newInstance(Class.java:1319)
08-05 02:58:28.001: E/AndroidRuntime(977): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-05 02:58:28.001: E/AndroidRuntime(977): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
08-05 02:58:28.001: E/AndroidRuntime(977): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-05 02:58:28.001: E/AndroidRuntime(977): at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-05 02:58:28.001: E/AndroidRuntime(977): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-05 02:58:28.001: E/AndroidRuntime(977): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 02:58:28.001: E/AndroidRuntime(977): at android.os.Looper.loop(Looper.java:137)
08-05 02:58:28.001: E/AndroidRuntime(977): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-05 02:58:28.001: E/AndroidRuntime(977): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 02:58:28.001: E/AndroidRuntime(977): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 02:58:28.001: E/AndroidRuntime(977): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-05 02:58:28.001: E/AndroidRuntime(977): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-05 02:58:28.001: E/AndroidRuntime(977): at dalvik.system.NativeStart.main(Native Method)
08-05 02:58:28.383: I/dalvikvm(977): threadid=3: reacting to signal 3
08-05 02:58:28.391: I/dalvikvm(977): Wrote stack traces to '/data/anr/traces.txt'
08-05 02:58:28.591: I/dalvikvm(977): threadid=3: reacting to signal 3
08-05 02:58:28.601: I/dalvikvm(977): Wrote stack traces to '/data/anr/traces.txt'
解决办法:
在工程的属性(File-Properties)页中,选“Java Build Path-Source”,然后“And Folder...”,选“libs”!