logcat 打出来的是: 01-06 02:26:35.908: WARN/dalvikvm(682): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/Android/oray/TestBaseThread/TestBaseThread; 01-06 02:26:44.005: WARN/dalvikvm(682): Class init failed in newInstance call (Lcom/Android/oray/TestBaseThread/TestBaseThread;) 01-06 02:29:42.724: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol 01-06 02:34:42.765: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol 01-06 02:36:49.765: DEBUG/dalvikvm(129): GC_CONCURRENT freed 308K, 53% free 2709K/5703K, external 931K/1038K, paused 30ms+8ms 01-06 02:39:29.614: VERBOSE/BackupManagerService(67): Backup requested but nothing pending 01-06 02:39:42.834: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol 01-06 02:44:00.724: DEBUG/dalvikvm(67): GC_CONCURRENT freed 769K, 47% free 4150K/7687K, external 2050K/2558K, paused 12ms+15ms 01-06 02:44:42.903: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol 01-06 02:47:34.994: DEBUG/dalvikvm(123): GC_CONCURRENT freed 434K, 52% free 2903K/6023K, external 716K/1038K, paused 43ms+10ms 01-06 02:49:42.944: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol 01-06 02:54:42.983: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol 01-06 02:59:43.015: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
刚才没仔细看loge里面也有异常,是库没加载成功吗 01-06 03:03:50.516: ERROR/AndroidRuntime(682): FATAL EXCEPTION: main 01-06 03:03:50.516: ERROR/AndroidRuntime(682): java.lang.ExceptionInInitializerError 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.Class.newInstanceImpl(Native Method) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.Class.newInstance(Class.java:1409) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.os.Handler.dispatchMessage(Handler.java:99) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.os.Looper.loop(Looper.java:123) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread.main(ActivityThread.java:3647) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.reflect.Method.invokeNative(Native Method) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.reflect.Method.invoke(Method.java:507) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at dalvik.system.NativeStart.main(Native Method) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load TestBaseThread_jni: findLibrary returned null 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.Runtime.loadLibrary(Runtime.java:429) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.System.loadLibrary(System.java:554) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): at com.Android.oray.TestBaseThread.TestBaseThread.<clinit>(TestBaseThread.java:9) 01-06 03:03:50.516: ERROR/AndroidRuntime(682): ... 15 more
01-06 02:26:35.908: WARN/dalvikvm(682): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/Android/oray/TestBaseThread/TestBaseThread;
01-06 02:26:44.005: WARN/dalvikvm(682): Class init failed in newInstance call (Lcom/Android/oray/TestBaseThread/TestBaseThread;)
01-06 02:29:42.724: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
01-06 02:34:42.765: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
01-06 02:36:49.765: DEBUG/dalvikvm(129): GC_CONCURRENT freed 308K, 53% free 2709K/5703K, external 931K/1038K, paused 30ms+8ms
01-06 02:39:29.614: VERBOSE/BackupManagerService(67): Backup requested but nothing pending
01-06 02:39:42.834: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
01-06 02:44:00.724: DEBUG/dalvikvm(67): GC_CONCURRENT freed 769K, 47% free 4150K/7687K, external 2050K/2558K, paused 12ms+15ms
01-06 02:44:42.903: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
01-06 02:47:34.994: DEBUG/dalvikvm(123): GC_CONCURRENT freed 434K, 52% free 2903K/6023K, external 716K/1038K, paused 43ms+10ms
01-06 02:49:42.944: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
01-06 02:54:42.983: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
01-06 02:59:43.015: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
01-06 03:03:50.516: ERROR/AndroidRuntime(682): FATAL EXCEPTION: main
01-06 03:03:50.516: ERROR/AndroidRuntime(682): java.lang.ExceptionInInitializerError
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.Class.newInstanceImpl(Native Method)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.Class.newInstance(Class.java:1409)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.os.Handler.dispatchMessage(Handler.java:99)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.os.Looper.loop(Looper.java:123)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at android.app.ActivityThread.main(ActivityThread.java:3647)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.reflect.Method.invokeNative(Native Method)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.reflect.Method.invoke(Method.java:507)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at dalvik.system.NativeStart.main(Native Method)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load TestBaseThread_jni: findLibrary returned null
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.Runtime.loadLibrary(Runtime.java:429)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at java.lang.System.loadLibrary(System.java:554)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): at com.Android.oray.TestBaseThread.TestBaseThread.<clinit>(TestBaseThread.java:9)
01-06 03:03:50.516: ERROR/AndroidRuntime(682): ... 15 more
UnsatisfiedLinkError 一般就是调用没有找到c实现的native函数出现的。
说的很有道理,但我刚才调了一下,把java代码加了异常捕获,如下: static {
try{
System.loadLibrary("TestBaseThread_jni");
}catch(UnsatisfiedLinkError ule){
System.err.println("WARNING: Could not load library 12425242!");
}
}
发现在logcat info里面打出了异常,那就是我连库都没加上,可是设置应该没问题啊。
LOCAL_LDLIBS := -lm -llog -L../libSTL_share.so(这个是NDK的STL库文件的位置)
这样就能在运行程序的时候链接上,就不会抛UnsatisfiedLinkError的异常了。
用windows内核函数啊,那比较难搞了,用虚拟机?
还是把你调内核那部分代码写成跨平台的吧
windows内核有的功能,linux基本上也有,只要用预编译处理下就行了。