首先,我想说我确实拥有互联网权限。
我尝试这样做
jcifs.Config.registerSmbURLHandler();
SmbFile file = new SmbFile("smb://");
SmbFile[] files = file.listFiles();
新的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
答案 0 :(得分:5)
&#34;引起:android.os.NetworkOnMainThreadException&#34;
您正试图在主线程上访问网络。有几种方法可以避免此错误,最推荐使用AsyncTask。
以下是AsyncTask上的文档。
http://developer.android.com/reference/android/os/AsyncTask.html
答案 1 :(得分:2)
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",
username, password);
sFile = new SmbFile(path, auth);
files = sFile.listFiles();
路径应该以smb:// ipadress / pathtosharefolder /
的形式给出用户名,密码 - 访问网络的用户名和密码