0

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
tantonj
  • 434
  • 5
  • 18
  • I think you're missing some dependencies. Since the project is open source can you see what happens at line 850 in SmbFile? Maybe that will help. – Gaurav Mar 25 '12 at 10:31
  • line 850 of SmbFile is if (address != null && address.length() > 0) { how could i be missing dependencies? I added the jar file for jcifs... apparently that's all you need to do – tantonj Mar 26 '12 at 00:03
  • Can you post the full trace on pastebin or somewhere else? I think a different exception is causing this error. – Gaurav Mar 26 '12 at 13:02
  • if someone have the same problem, here is the anwser: http://stackoverflow.com/questions/8706464/defaulthttpclient-to-androidhttpclient – Stefhan Sep 21 '13 at 15:45
  • if someone have the same problem, here is the anwser: http://stackoverflow.com/questions/8706464/defaulthttpclient-to-androidhttpclient – Stefhan Sep 21 '13 at 15:47

2 Answers2

5

"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

2
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",
            username, password);

sFile = new SmbFile(path, auth);

files = sFile.listFiles();

path should be given as smb://ipadress/pathtosharefolder/

username,password -- username and password to access the network

rwe
  • 177
  • 1
  • 1
  • 11
  • So currently my Asus transformers USB cord has stopped working for data transmission. So until my new cord comes in I can't test with auth... I did however try this half a week ago using a windows app, and it worked with authentication, but wasn't able to list files from smb:// so I'll probably be able to get it going once my new cord comes in – tantonj Apr 05 '12 at 18:23