我正在尝试使用smb开发一个Android应用程序。我试图列出局域网中可用的网络位置。我正在使用以下代码来执行此操作:
SmbFile[] domains;
domains = (new SmbFile("smb://")).listFiles();
for (int i = 0; i < domains.length; i++) {
SmbFile[] servers;
try {
servers = domains[i].listFiles();
} catch (SmbException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int j = 0; j < servers.length; j++) {
System.out.println("Network places.... " +servers[j].getName());
}
}
} catch (SmbException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我正在获取网络列表,但随机出现以下异常:
08-21 12:12:22.336: W/System.err(10141): jcifs.smb.SmbException: Failed to negotiate
08-21 12:12:22.336: W/System.err(10141): jcifs.smb.SmbException: Timeout trying to open socket
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbTransport.start(SmbTransport.java:315)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbTransport.negotiate0(SmbTransport.java:865)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:941)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbTree.treeConnect(SmbTree.java:119)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbFile.connect(SmbFile.java:827)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbFile.connect0(SmbFile.java:797)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbFile.doNetEnum(SmbFile.java:1634)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbFile.listFiles(SmbFile.java:1604)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbFile.listFiles(SmbFile.java:1514)
08-21 12:12:22.336: W/System.err(10141): at com.lnt.ts.explorer.FileExplorerActivity$ConnectToServer.doInBackground(FileExplorerActivity.java:108)
08-21 12:12:22.336: W/System.err(10141): at com.lnt.ts.explorer.FileExplorerActivity$ConnectToServer.doInBackground(FileExplorerActivity.java:1)
08-21 12:12:22.336: W/System.err(10141): at android.os.AsyncTask$2.call(AsyncTask.java:288)
08-21 12:12:22.336: W/System.err(10141): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-21 12:12:22.336: W/System.err(10141): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
08-21 12:12:22.336: W/System.err(10141): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-21 12:12:22.336: W/System.err(10141): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-21 12:12:22.336: W/System.err(10141): at java.lang.Thread.run(Thread.java:841)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:947)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbTree.treeConnect(SmbTree.java:119)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbFile.connect(SmbFile.java:827)
08-21 12:12:22.336: W/System.err(10141): at jcifs.smb.SmbFile.connect0(SmbFile.java:797)
08-21 12:12:22.341: W/System.err(10141): at jcifs.smb.SmbFile.doNetEnum(SmbFile.java:1634)
08-21 12:12:22.341: W/System.err(10141): at jcifs.smb.SmbFile.listFiles(SmbFile.java:1604)
08-21 12:12:22.341: W/System.err(10141): at jcifs.smb.SmbFile.listFiles(SmbFile.java:1514)
08-21 12:12:22.341: W/System.err(10141): at com.lnt.ts.explorer.FileExplorerActivity$ConnectToServer.doInBackground(FileExplorerActivity.java:108)
08-21 12:12:22.341: W/System.err(10141): at com.lnt.ts.explorer.FileExplorerActivity$ConnectToServer.doInBackground(FileExplorerActivity.java:1)
08-21 12:12:22.341: W/System.err(10141): at android.os.AsyncTask$2.call(AsyncTask.java:288)
08-21 12:12:22.341: W/System.err(10141): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-21 12:12:22.341: W/System.err(10141): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
08-21 12:12:22.341: W/System.err(10141): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-21 12:12:22.341: W/System.err(10141): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-21 12:12:22.341: W/System.err(10141): at java.lang.Thread.run(Thread.java:841)
我无法弄清楚如何解决此异常(谷歌搜索很多没有运气)。请建议我如何解决此异常。提前谢谢。
答案 0 :(得分:0)
确保您使用的是最新的jar,现在是jcifs-1.3.15.jar,而不是jcifs-1.1.11.jar等较低版本