我试图登录到我的Windows服务器中使用JCIFS下载文件。 该应用程序工作正常,在我的Android 2.2手机和一个老2.3的平板电脑。 我刚刚购买了乐潘II我升级到了4.0.3。 当我尝试运行我的应用程序它的崩溃试图访问服务器时。 有没有什么新的东西,我需要为4.0.3呢? 我试着注释掉属于输出流,以确保它是输入端导致了问题的一切。 如果我注释掉里面的东西最里面的try块一切工作正常,所以它的东西在里面。 只要我去掉的InputStream在= file.getInputStream(); 然后崩溃。
权限清单文件。
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"/>
下载功能
public static String DlFile() {
SmbFile file = null;
try {
file = new SmbFile("smb://NAME:PASSWORD@10.0.0.4/jws/Data/Inspection Reports/forms/0990125.txt");
Log.v(TAG, "smbFile: " + file.toString());
try {
InputStream in = file.getInputStream();
FileOutputStream out = new FileOutputStream(cfgSDFolder + myFile);
byte[] b = new byte[8192];
int n;
while(( n = in.read( b )) > 0 ) {
out.write( b, 0, n );
}
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
Log.v(TAG, "DSZerror: " + e.getMessage().toString());
return "error: " + e.getMessage().toString();
}
} catch (MalformedURLException e) {
e.printStackTrace();
Log.v(TAG, "DSZerror:" + e.getMessage().toString());
return "error: " + e.getMessage().toString();
} // note the different format
return "ok";
}
错误
08-21 18:39:50.548: W/dalvikvm(4604): Exception Landroid/os/NetworkOnMainThreadException; thrown while initializing Ljcifs/netbios/NbtAddress;
08-21 18:39:50.548: W/dalvikvm(4604): Exception Ljava/lang/ExceptionInInitializerError; thrown while initializing Ljcifs/UniAddress;
08-21 18:39:50.548: W/dalvikvm(4604): threadid=1: thread exiting with uncaught exception (group=0x40a871f8)
08-21 18:39:50.578: E/AndroidRuntime(4604): FATAL EXCEPTION: main
08-21 18:39:50.578: E/AndroidRuntime(4604): java.lang.ExceptionInInitializerError
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:864)
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.smb.SmbFile.connect(SmbFile.java:951)
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.smb.SmbFile.open0(SmbFile.java:972)
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.smb.SmbFile.open(SmbFile.java:1006)
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.smb.SmbFile.getInputStream(SmbFile.java:2844)
08-21 18:39:50.578: E/AndroidRuntime(4604): at com.thedsz.jws.qc.DSZ.DlFile(DSZ.java:58)
08-21 18:39:50.578: E/AndroidRuntime(4604): at com.thedsz.jws.qc.Splash$2.afterTextChanged(Splash.java:99)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.widget.TextView.sendAfterTextChanged(TextView.java:7655)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8057)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.text.SpannableStringBuilder.sendTextHasChanged(SpannableStringBuilder.java:900)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:353)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:266)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:443)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:420)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:29)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.text.method.NumberKeyListener.onKeyDown(NumberKeyListener.java:117)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.widget.TextView.doKeyDown(TextView.java:5445)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.widget.TextView.onKeyDown(TextView.java:5267)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.KeyEvent.dispatch(KeyEvent.java:2566)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.View.dispatchKeyEvent(View.java:5500)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
08-21 18:39:50.578: E/AndroidRuntime(4604): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1879)
08-21 18:39:50.578: E/AndroidRuntime(4604): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1361)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.app.Activity.dispatchKeyEvent(Activity.java:2324)
08-21 18:39:50.578: E/AndroidRuntime(4604): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1806)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3327)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2597)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.os.Looper.loop(Looper.java:137)
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-21 18:39:50.578: E/AndroidRuntime(4604): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 18:39:50.578: E/AndroidRuntime(4604): at java.lang.reflect.Method.invoke(Method.java:511)
08-21 18:39:50.578: E/AndroidRuntime(4604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
08-21 18:39:50.578: E/AndroidRuntime(4604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
08-21 18:39:50.578: E/AndroidRuntime(4604): at dalvik.system.NativeStart.main(Native Method)
08-21 18:39:50.578: E/AndroidRuntime(4604): Caused by: java.lang.ExceptionInInitializerError
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.UniAddress.<clinit>(UniAddress.java:62)
08-21 18:39:50.578: E/AndroidRuntime(4604): ... 43 more
08-21 18:39:50.578: E/AndroidRuntime(4604): Caused by: android.os.NetworkOnMainThreadException
08-21 18:39:50.578: E/AndroidRuntime(4604): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
08-21 18:39:50.578: E/AndroidRuntime(4604): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
08-21 18:39:50.578: E/AndroidRuntime(4604): at java.net.InetAddress.getLocalHost(InetAddress.java:371)
08-21 18:39:50.578: E/AndroidRuntime(4604): at jcifs.netbios.NbtAddress.<clinit>(NbtAddress.java:187)
08-21 18:39:50.578: E/AndroidRuntime(4604): ... 44 more