问题描述
首先,我想说我有在互联网上的权限。
我尝试这样做。
jcifs.Config.registerSmbURLHandler();
SmbFile文件=新SmbFile(SMB://);
SmbFile [] =文件file.listFiles();
新SmbFile(...)执行罚款,当file.listFiles()尝试运行并出现以下错误崩溃...
二月3日至25日:47:17.749:E / AndroidRuntime(4552):致命异常:主要
2月3日至25日:47:17.749:E / AndroidRuntime(4552):java.lang.ExceptionInInitializerError
2月3日至25日:47:17.749:E / AndroidRuntime(4552):在jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:850)
2月3日至25日:47:17.749:E / AndroidRuntime(4552):在jcifs.smb.SmbFile.connect(SmbFile.java:951)
2月3日至25日:47:17.749:E / AndroidRuntime(4552):在jcifs.smb.SmbFile.connect0(SmbFile.java:880)
2月3日至25日:47:17.749:E / AndroidRuntime(4552):在jcifs.smb.SmbFile.doNetServerEnum(SmbFile.java:1914)
2月3日至25日:47:17.749:E / AndroidRuntime(4552):在jcifs.smb.SmbFile.doEnum(SmbFile.java:1734)
2月3日至25日:47:17.749:E / AndroidRuntime(4552):在jcifs.smb.SmbFile.listFiles(SmbFile.java:1715)
2月3日至25日:47:17.749:E / AndroidRuntime(4552):在jcifs.smb.SmbFile.listFiles(SmbFile.java:1648)
那么,这不连接?我不知道为什么这是发生的,我scowered互联网。找不到任何人谁了这个问题,在这之前...
通过评论的要求在这里坠毁以下错误的整个列表
03-26 21:15:00.140:E / AndroidRuntime(9691):致命异常:主要
03-26 21:15:00.140:E / AndroidRuntime(9691):java.lang.ExceptionInInitializerError
03-26 21:15:00.140:E / AndroidRuntime(9691):在jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:850)
03-26 21:15:00.140:E / AndroidRuntime(9691):在jcifs.smb.SmbFile.connect(SmbFile.java:951)
03-26 21:15:00.140:E / AndroidRuntime(9691):在jcifs.smb.SmbFile.connect0(SmbFile.java:880)
03-26 21:15:00.140:E / AndroidRuntime(9691):在jcifs.smb.SmbFile.doNetServerEnum(SmbFile.java:1914)
03-26 21:15:00.140:E / AndroidRuntime(9691):在jcifs.smb.SmbFile.doEnum(SmbFile.java:1734)
03-26 21:15:00.140:E / AndroidRuntime(9691):在jcifs.smb.SmbFile.listFiles(SmbFile.java:1715)
03-26 21:15:00.140:E / AndroidRuntime(9691):在jcifs.smb.SmbFile.listFiles(SmbFile.java:1648)
03-26 21:15:00.140:E / AndroidRuntime(9691):在tantonj.ComicXtreamHD.NRootPick.fill(NRootPick.java:37)
03-26 21:15:00.140:E / AndroidRuntime(9691):在tantonj.ComicXtreamHD.NRootPick.onCreate(NRootPick.java:26)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.app.Activity.performCreate(Activity.java:4465)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.app.ActivityThread.access $ 600(ActivityThread.java:123)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.os.Handler.dispatchMessage(Handler.java:99)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.os.Looper.loop(Looper.java:137)
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.app.ActivityThread.main(ActivityThread.java:4424)
03-26 21:15:00.140:E / AndroidRuntime(9691):在java.lang.reflect.Method.invokeNative(本机方法)
03-26 21:15:00.140:E / AndroidRuntime(9691):在java.lang.reflect.Method.invoke(Method.java:511)
03-26 21:15:00.140:E / AndroidRuntime(9691):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
03-26 21:15:00.140:E / AndroidRuntime(9691):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-26 21:15:00.140:E / AndroidRuntime(9691):在dalvik.system.NativeStart.main(本机方法)
03-26 21:15:00.140:E / AndroidRuntime(9691):因:android.os.NetworkOnMainThreadException
03-26 21:15:00.140:E / AndroidRuntime(9691):在android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
03-26 21:15:00.140:E / AndroidRuntime(9691):在java.net.InetAddress.lookupHostByName(InetAddress.java:391)
03-26 21:15:00.140:E / AndroidRuntime(9691):在java.net.InetAddress.getLocalHost(InetAddress.java:371)
03-26 21:15:00.140:E / AndroidRuntime(9691):在jcifs.netbios.NbtAddress< clinit>(NbtAddress.java:187)
03-26 21:15:00.140:E / AndroidRuntime(9691):23 ...更多
产生的原因:android.os.NetworkOnMainThreadException
您试图访问网络,而你的主线程上。有几种方法,以避免与最值得推荐的是使用的AsyncTask这个错误。
下面是对的AsyncTask的文档。
Firstly I would like to say I do have the Internet Permissions on.
I try to do this
jcifs.Config.registerSmbURLHandler();
SmbFile file = new SmbFile("smb://");
SmbFile[] files = file.listFiles();
new SmbFile(...) executes fine, when file.listFiles() attempts to run it crashes with the following error...
03-25 02:47:17.749: E/AndroidRuntime(4552): FATAL EXCEPTION: main
03-25 02:47:17.749: E/AndroidRuntime(4552): java.lang.ExceptionInInitializerError
03-25 02:47:17.749: E/AndroidRuntime(4552): at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:850)
03-25 02:47:17.749: E/AndroidRuntime(4552): at jcifs.smb.SmbFile.connect(SmbFile.java:951)
03-25 02:47:17.749: E/AndroidRuntime(4552): at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
03-25 02:47:17.749: E/AndroidRuntime(4552): at jcifs.smb.SmbFile.doNetServerEnum(SmbFile.java:1914)
03-25 02:47:17.749: E/AndroidRuntime(4552): at jcifs.smb.SmbFile.doEnum(SmbFile.java:1734)
03-25 02:47:17.749: E/AndroidRuntime(4552): at jcifs.smb.SmbFile.listFiles(SmbFile.java:1715)
03-25 02:47:17.749: E/AndroidRuntime(4552): at jcifs.smb.SmbFile.listFiles(SmbFile.java:1648)
So Is It not connecting? I am not sure why this is occuring, I've scowered the internet. Can't find anyone who had this problem with this before...
as requested by comment here is the entire list of errors following the crash
03-26 21:15:00.140: E/AndroidRuntime(9691): FATAL EXCEPTION: main
03-26 21:15:00.140: E/AndroidRuntime(9691): java.lang.ExceptionInInitializerError
03-26 21:15:00.140: E/AndroidRuntime(9691): at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:850)
03-26 21:15:00.140: E/AndroidRuntime(9691): at jcifs.smb.SmbFile.connect(SmbFile.java:951)
03-26 21:15:00.140: E/AndroidRuntime(9691): at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
03-26 21:15:00.140: E/AndroidRuntime(9691): at jcifs.smb.SmbFile.doNetServerEnum(SmbFile.java:1914)
03-26 21:15:00.140: E/AndroidRuntime(9691): at jcifs.smb.SmbFile.doEnum(SmbFile.java:1734)
03-26 21:15:00.140: E/AndroidRuntime(9691): at jcifs.smb.SmbFile.listFiles(SmbFile.java:1715)
03-26 21:15:00.140: E/AndroidRuntime(9691): at jcifs.smb.SmbFile.listFiles(SmbFile.java:1648)
03-26 21:15:00.140: E/AndroidRuntime(9691): at tantonj.ComicXtreamHD.NRootPick.fill(NRootPick.java:37)
03-26 21:15:00.140: E/AndroidRuntime(9691): at tantonj.ComicXtreamHD.NRootPick.onCreate(NRootPick.java:26)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.app.Activity.performCreate(Activity.java:4465)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.os.Looper.loop(Looper.java:137)
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-26 21:15:00.140: E/AndroidRuntime(9691): at java.lang.reflect.Method.invokeNative(Native Method)
03-26 21:15:00.140: E/AndroidRuntime(9691): at java.lang.reflect.Method.invoke(Method.java:511)
03-26 21:15:00.140: E/AndroidRuntime(9691): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-26 21:15:00.140: E/AndroidRuntime(9691): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-26 21:15:00.140: E/AndroidRuntime(9691): at dalvik.system.NativeStart.main(Native Method)
03-26 21:15:00.140: E/AndroidRuntime(9691): Caused by: android.os.NetworkOnMainThreadException
03-26 21:15:00.140: E/AndroidRuntime(9691): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
03-26 21:15:00.140: E/AndroidRuntime(9691): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
03-26 21:15:00.140: E/AndroidRuntime(9691): at java.net.InetAddress.getLocalHost(InetAddress.java:371)
03-26 21:15:00.140: E/AndroidRuntime(9691): at jcifs.netbios.NbtAddress.<clinit>(NbtAddress.java:187)
03-26 21:15:00.140: E/AndroidRuntime(9691): ... 23 more
"Caused by: android.os.NetworkOnMainThreadException"
You are trying to access a Network while on your main thread. There are several ways to avoid this error with the most recommended being to use AsyncTask.
Here are the docs on AsyncTask.
http://developer.android.com/reference/android/os/AsyncTask.html
这篇关于JCIFS SmbFile.listFiles崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!