0

首先,我想说我确实拥有 Internet 权限。

我试着这样做

jcifs.Config.registerSmbURLHandler();
SmbFile file = new SmbFile("smb://");
SmbFile[] files = file.listFiles();

new SmbFile(...) 执行良好,当 file.listFiles() 尝试运行时它会崩溃并出现以下错误...

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)

那么它没有连接吗?我不确定为什么会发生这种情况,我已经浏览了互联网。之前找不到遇到这个问题的人...

正如评论所要求的,这里是崩溃后的完整错误列表

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
4

2 回答 2

5

“引起:android.os.NetworkOnMainThreadException”

您正在尝试在主线程上访问网络。有几种方法可以避免此错误,最推荐的是使用 AsyncTask。

这是关于 AsyncTask 的文档。

http://developer.android.com/reference/android/os/AsyncTask.html

于 2014-04-29T14:57:01.320 回答
2
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",
            username, password);

sFile = new SmbFile(path, auth);

files = sFile.listFiles();

路径应为 smb://ipadress/pathtosharefolder/

username,password -- 访问网络的用户名和密码

于 2012-04-05T04:46:28.797 回答