Android Xamarin保存文件到windows共享
本文关键字:windows 共享 保存文件 Xamarin Android | 更新日期: 2023-09-27 17:54:34
我在Visual Studio 2015中有一个Xamarin c#项目,使我的Android应用程序使用jCIFS将文件保存到Windows共享文件夹。
这是我用来保存文件的方法:
private async Task Save2Samba(string text)
{
String sSambaFolder = "192.168.0.22/c";
String url = "smb://" + sSambaFolder + "/file.txt";
byte[] bytes = new byte[text.Length * sizeof(char)];
System.Buffer.BlockCopy(text.ToCharArray(), 0, bytes, 0, bytes.Length);
SmbFile file = null;
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, null, null);
file = new SmbFile(url, auth);
SmbFileOutputStream lol = new SmbFileOutputStream(file);
lol.Write(bytes);
lol.Flush();
lol.Close();
}
在运行时,我初始化SmbFileOutputStream
的那行抛出一个Java.Lang.ExceptionInInitializerError
,错误堆栈如下
Unhandled Exception:
Java.Lang.ExceptionInInitializerError:
07-04 23:10:20.018 D/Mono (22361): Image addref System.Runtime.Serialization[0xb4ab2f40] -> System.Runtime.Serialization.dll[0xb4840200]: 1
07-04 23:10:20.018 D/Mono (22361): Assembly System.Runtime.Serialization[0xb4ab2f40] added to domain RootDomain, ref_count=1
07-04 23:10:20.027 D/Mono (22361): AOT module 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/FinalInspection_Droid_Aufbau.FinalInspection_Droid_Aufbau-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
07-04 23:10:20.036 D/Mono (22361): AOT module '/Users/builder/data/lanes/2923/52635947/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/FinalInspection_Droid_Aufbau.FinalInspection_Droid_Aufbau-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
07-04 23:10:20.040 D/Mono (22361): Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
07-04 23:10:20.040 D/Mono (22361): Config attempting to parse: '/Users/builder/data/lanes/2923/52635947/source/monodroid/builds/install/mono-armv7/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
07-04 23:10:20.040 D/Mono (22361): Assembly Ref addref Mono.Android[0xb4b214c0] -> System.Runtime.Serialization[0xb4ab2f40]: 2
07-04 23:10:20.041 D/Mono (22361): Assembly Ref addref System.Runtime.Serialization[0xb4ab2f40] -> mscorlib[0xb4ab2b80]: 17
Loaded assembly: System.Runtime.Serialization.dll [External]
07-04 23:10:23.720 D/Mono (22361): DllImport attempting to load: '/system/lib/liblog.so'.
07-04 23:10:23.721 D/Mono (22361): DllImport loaded library '/system/lib/liblog.so'.
07-04 23:10:23.725 D/Mono (22361): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
07-04 23:10:23.725 D/Mono (22361): Searching for '__android_log_print'.
07-04 23:10:23.725 D/Mono (22361): Probing '__android_log_print'.
07-04 23:10:23.725 D/Mono (22361): Found as '__android_log_print'.
07-04 23:10:23.734 I/MonoDroid(22361): UNHANDLED EXCEPTION:
07-04 23:10:23.743 I/MonoDroid(22361): Java.Lang.ExceptionInInitializerError: Exception of type 'Java.Lang.ExceptionInInitializerError' was thrown. ---> Android.OS.NetworkOnMainThreadException: Exception of type 'Android.OS.NetworkOnMainThreadException' was thrown.
07-04 23:10:23.743 I/MonoDroid(22361): --- End of managed exception stack trace ---
07-04 23:10:23.743 I/MonoDroid(22361): android.os.NetworkOnMainThreadException
07-04 23:10:23.743 I/MonoDroid(22361): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
07-04 23:10:23.743 I/MonoDroid(22361): at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
07-04 23:10:23.743 I/MonoDroid(22361): at java.net.InetAddress.getLocalHost(InetAddress.java:396)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.netbios.NbtAddress.<clinit>(NbtAddress.java:187)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.netbios.NbtAddress.getWINSAddress(NbtAddress.java:533)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.UniAddress.<clinit>(UniAddress.java:62)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:864)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.smb.SmbFile.connect(SmbFile.java:951)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.smb.SmbFile.open0(SmbFile.java:972)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.smb.SmbFile.open(SmbFile.java:1006)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:97)
07-04 23:10:23.743 I/MonoDroid(22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:67)
07-04 23:10:23.743 I/MonoDroid(22361): at md5ac18087b2af203d2f41df0f73b22a485.BodyInspectionForm_TabFragment.n_onOptionsItemSelected(Native Method)
07-04 23:10:23.743 I/MonoDroid(22361): at md5ac18087b2af203d2f41df0f73b22a485.BodyInspectionForm_TabFragment.onOptionsItemSelected(BodyInspectionForm_TabFragment.java:47)
07-04 23:10:23.743 I/MonoDroid(22361): at android.app.Fragment.performOptionsItemSelected(Fragment.java:2159)
07-04 23:10:23.743 I/MonoDroid(22361): at android.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:1988)
07-04 23:10:23.743 I/MonoDroid(22361): at android.app.Activity.onMenuItemSelected(Activity.java:2970)
07-04 23:10:23.743 I/MonoDroid(22361): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1136)
07-04 23:10:23.743 I/MonoDroid(22361): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
07-04 23:10:23.743 I/MonoDroid(22361): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
07-04 23:10:23.743 I/MonoDroid(22361): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
07-04 23:10:23.743 I/MonoDroid(22361): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
07-04 23:10:23.743 I/MonoDroid(22361): at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:186)
07-04 23:10:23.743 I/MonoDroid(22361): at android.widget.AdapterView.performItemClick(AdapterView.java:305)
07-04 23:10:23.743 I/MonoDroid(22361): at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
07-04 23:10:23.743 I/MonoDroid(22361): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3057)
07-04 23:10:23.743 I/MonoDroid(22361): at android.widget.AbsListView$3.run(AbsListView.java:3864)
07-04 23:10:23.744 I/MonoDroid(22361): at android.os.Handler.handleCallback(Handler.java:739)
07-04 23:10:23.744 I/MonoDroid(22361): at android.os.Handler.dispatchMessage(Handler.java:95)
07-04 23:10:23.744 I/MonoDroid(22361): at android.os.Looper.loop(Looper.java:139)
07-04 23:10:23.744 I/MonoDroid(22361): at android.app.ActivityThread.main(ActivityThread.java:5298)
07-04 23:10:23.744 I/MonoDroid(22361): at java.lang.reflect.Method.invoke(Native Method)
07-04 23:10:23.744 I/MonoDroid(22361): at java.lang.reflect.Method.invoke(Method.java:372)
07-04 23:10:23.744 I/MonoDroid(22361): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
07-04 23:10:23.744 I/MonoDroid(22361): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
07-04 23:10:23.744 I/MonoDroid(22361): --- End of inner exception stack trace ---
07-04 23:10:23.744 I/MonoDroid(22361): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
07-04 23:10:23.744 I/MonoDroid(22361): at Java.Interop.JniEnvironment+Object._NewObject (JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00085] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12200
07-04 23:10:23.744 I/MonoDroid(22361): at Java.Interop.JniEnvironment+Object.NewObject (JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0000b] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.Object.cs:33
07-04 23:10:23.744 I/MonoDroid(22361): at Android.Runtime.JNIEnv.NewObject (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/data/lanes/3340/4e275588/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:768
07-04 23:10:23.744 I/MonoDroid(22361): at Android.Runtime.JNIEnv.NewObject (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x0001d] in /Users/builder/data/lanes/3340/4e275588/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:786
07-04 23:10:23.744 I/MonoDroid(22361): at Jcifs.Smb.SmbFileOutputStream..ctor (Jcifs.Smb.SmbFile p0) [0x000b1] in <filename unknown>:0
07-04 23:10:23.744 I/MonoDroid(22361): at FinalInspection_Droid_Aufbau.BodyInspectionForm+TabFragment.Save2Samba (System.String text) [0x0004d] in E:'dlouhy'Documents'Projects'mitsenden'FinalInspection_Aufbau'Phoneword_Droid'BodyInspectionForm.cs:1527
07-04 23:10:23.744 I/MonoDroid(22361): at FinalInspection_Droid_Aufbau.BodyInspectionForm+TabFragment.OnOptionsItemSelected (IMenuItem item) [0x0004e] in E:'dlouhy'Documents'Projects'mitsenden'FinalInspection_Aufbau'Phoneword_Droid'BodyInspectionForm.cs:1220
07-04 23:10:23.744 I/MonoDroid(22361): at Android.App.Fragment.n_OnOptionsItemSelected_Landroid_view_MenuItem_ (IntPtr jnienv, IntPtr native__this, IntPtr native_item) [0x00011] in /Users/builder/data/lanes/3340/4e275588/source/monodroid/src/Mono.Android/platforms/android-17/src/generated/Android.App.Fragment.cs:1350
07-04 23:10:23.744 I/MonoDroid(22361): at (wrapper dynamic-method) System.Object:15133db7-418a-4549-88a0-cddc3cc27dfe (intptr,intptr,intptr)
07-04 23:10:23.744 I/MonoDroid(22361): --- End of managed exception stack trace ---
07-04 23:10:23.744 I/MonoDroid(22361): java.lang.ExceptionInInitializerError
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.netbios.NbtAddress.getWINSAddress(NbtAddress.java:533)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.UniAddress.<clinit>(UniAddress.java:62)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:864)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.smb.SmbFile.connect(SmbFile.java:951)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.smb.SmbFile.open0(SmbFile.java:972)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.smb.SmbFile.open(SmbFile.java:1006)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:97)
07-04 23:10:23.744 I/MonoDroid(22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:67)
07-04 23:10:23.744 I/MonoDroid(22361): at md5ac18087b2af203d2f41df0f73b22a485.BodyInspectionForm_TabFragment.n_onOptionsItemSelected(Native Method)
07-04 23:10:23.744 I/MonoDroid(22361): at md5ac18087b2af203d2f41df0f73b22a485.BodyInspectionForm_TabFragment.onOptionsItemSelected(BodyInspectionForm_TabFragment.java:47)
07-04 23:10:23.744 I/MonoDroid(22361): at android.app.Fragment.performOptionsItemSelected(Fragment.java:2159)
07-04 23:10:23.744 I/MonoDroid(22361): at android.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:1988)
07-04 23:10:23.744 I/MonoDroid(22361): at android.app.Activity.onMenuItemSelected(Activity.java:2970)
07-04 23:10:23.745 I/MonoDroid(22361): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1136)
07-04 23:10:23.745 I/MonoDroid(22361): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
07-04 23:10:23.745 I/MonoDroid(22361): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
07-04 23:10:23.745 I/MonoDroid(22361): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
07-04 23:10:23.745 I/MonoDroid(22361): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
07-04 23:10:23.745 I/MonoDroid(22361): at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:186)
07-04 23:10:23.745 I/MonoDroid(22361): at android.widget.AdapterView.performItemClick(AdapterView.java:305)
07-04 23:10:23.745 I/MonoDroid(22361): at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
07-04 23:10:23.745 I/MonoDroid(22361): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3057)
07-04 23:10:23.745 I/MonoDroid(22361): at android.widget.AbsListView$3.run(AbsListView.java:3864)
07-04 23:10:23.745 I/MonoDroid(22361): at android.os.Handler.handleCallback(Handler.java:739)
07-04 23:10:23.745 I/MonoDroid(22361): at android.os.Handler.dispatchMessage(Handler.java:95)
07-04 23:10:23.745 I/MonoDroid(22361): at android.os.Looper.loop(Looper.java:139)
07-04 23:10:23.745 I/MonoDroid(22361): at android.app.ActivityThread.main(ActivityThread.java:5298)
07-04 23:10:23.745 I/MonoDroid(22361): at java.lang.reflect.Method.invoke(Native Method)
07-04 23:10:23.745 I/MonoDroid(22361): at java.lang.reflect.Method.invoke(Method.java:372)
07-04 23:10:23.745 I/MonoDroid(22361): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
07-04 23:10:23.745 I/MonoDroid(22361): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
07-04 23:10:23.745 I/MonoDroid(22361): Caused by: android.os.NetworkOnMainThreadException
07-04 23:10:23.745 I/MonoDroid(22361): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
07-04 23:10:23.745 I/MonoDroid(22361): at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
07-04 23:10:23.745 I/MonoDroid(22361): at java.net.InetAddress.getLocalHost(InetAddress.java:396)
07-04 23:10:23.745 I/MonoDroid(22361): at jcifs.netbios.NbtAddress.<clinit>(NbtAddress.java:187)
07-04 23:10:23.745 I/MonoDroid(22361): ... 33 more
07-04 23:10:23.758 D/Mono (22361): DllImport searching in: '__Internal' ('(null)').
07-04 23:10:23.758 D/Mono (22361): Searching for 'java_interop_jnienv_throw'.
07-04 23:10:23.758 D/Mono (22361): Probing 'java_interop_jnienv_throw'.
07-04 23:10:23.759 D/Mono (22361): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.
referenceTable GDEF length=670 1
referenceTable GSUB length=7202 1
referenceTable GPOS length=24560 1
referenceTable head length=54 1
referenceTable GDEF length=670 1
referenceTable GSUB length=7186 1
referenceTable GPOS length=26464 1
referenceTable head length=54 1
07-04 23:10:24.571 E/mono (22361):
07-04 23:10:24.571 E/mono (22361): Unhandled Exception:
07-04 23:10:24.571 E/mono (22361): Java.Lang.ExceptionInInitializerError: Exception of type 'Java.Lang.ExceptionInInitializerError' was thrown. ---> Android.OS.NetworkOnMainThreadException: Exception of type 'Android.OS.NetworkOnMainThreadException' was thrown.
07-04 23:10:24.571 E/mono (22361):
07-04 23:10:24.571 E/mono (22361): --- End of managed exception stack trace ---
07-04 23:10:24.571 E/mono (22361): android.os.NetworkOnMainThreadException
07-04 23:10:24.571 E/mono (22361): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
07-04 23:10:24.571 E/mono (22361): at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
07-04 23:10:24.571 E/mono (22361): at java.net.InetAddress.getLocalHost(InetAddress.java:396)
07-04 23:10:24.571 E/mono (22361): at jcifs.netbios.NbtAddress.<clinit>(NbtAddress.java:187)
07-04 23:10:24.571 E/mono (22361): at jcifs.netbios.NbtAddress.getWINSAddress(NbtAddress.java:533)
07-04 23:10:24.571 E/mono (22361): at jcifs.UniAddress.<clinit>(UniAddress.java:62)
07-04 23:10:24.571 E/mono (22361): at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:864)
07-04 23:10:24.571 E/mono (22361): at jcifs.smb.SmbFile.connect(SmbFile.java:951)
07-04 23:10:24.571 E/mono (22361): at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
07-04 23:10:24.571 E/mono (22361): at jcifs.smb.SmbFile.open0(SmbFile.java:972)
07-04 23:10:24.571 E/mono (22361): at jcifs.smb.SmbFile.open(SmbFile.java:1006)
07-04 23:10:24.571 E/mono (22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142)
07-04 23:10:24.571 E/mono (22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:97)
07-04 23:10:24.571 E/mono (22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:67)
07-04 23:10:24.571 E/mono (22361): at md5ac18087b2af203d2f41df0f73b22a485.BodyInspectionForm_TabFragment.n_onOptionsItemSelected(Native Method)
07-04 23:10:24.571 E/mono (22361): at md5ac18087b2af203d2f41df0f73b22a485.BodyInspectionForm_TabFragment.onOptionsItemSelected(BodyInspectionForm_TabFragment.java:47)
07-04 23:10:24.571 E/mono (22361): at android.app.Fragment.performOptionsItemSelected(Fragment.java:2159)
07-04 23:10:24.571 E/mono (22361): at android.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:1988)
07-04 23:10:24.571 E/mono (22361): at android.app.Activity.onMenuItemSelected(Activity.java:2970)
07-04 23:10:24.571 E/mono (22361): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1136)
07-04 23:10:24.571 E/mono (22361): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
07-04 23:10:24.571 E/mono (22361): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
07-04 23:10:24.571 E/mono (22361): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
07-04 23:10:24.571 E/mono (22361): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
07-04 23:10:24.571 E/mono (22361): at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:186)
07-04 23:10:24.571 E/mono (22361): at android.widget.AdapterView.performItemClick(AdapterView.java:305)
07-04 23:10:24.571 E/mono (22361): at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
07-04 23:10:24.571 E/mono (22361): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3057)
07-04 23:10:24.571 E/mono (22361): at android.widget.AbsListView$3.run(AbsListView.java:3864)
07-04 23:10:24.571 E/mono (22361): at android.os.Handler.handleCallback(Handler.java:739)
07-04 23:10:24.571 E/mono (22361): at android.os.Handler.dispatchMessage(Handler.java:95)
07-04 23:10:24.571 E/mono (22361): at android.os.Looper.loop(Looper.java:139)
07-04 23:10:24.571 E/mono (22361): at android.app.ActivityThread.main(ActivityThread.java:5298)
07-04 23:10:24.571 E/mono (22361): at java.lang.reflect.Method.invoke(Native Method)
07-04 23:10:24.571 E/mono (22361): at java.lang.reflect.Method.invoke(Method.java:372)
07-04 23:10:24.571 E/mono (22361): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
07-04 23:10:24.571 E/mono (22361): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
07-04 23:10:24.571 E/mono (22361):
07-04 23:10:24.571 E/mono (22361): --- End of inner exception stack trace ---
07-04 23:10:24.571 E/mono (22361): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
07-04 23:10:24.571 E/mono (22361): at Java.Interop.JniEnvironment+Object._NewObject (JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00085] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12200
07-04 23:10:24.571 E/mono (22361): at Java.Interop.JniEnvironment+Object.NewObject (JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0000b] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.Object.cs:33
07-04 23:10:24.571 E/mono (22361): at Android.Runtime.JNIEnv.NewObject (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/data/lanes/3340/4e275588/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:768
07-04 23:10:24.571 E/mono (22361): at Android.Runtime.JNIEnv.NewObject (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0
07-04 23:10:24.571 E/mono-rt (22361): [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.ExceptionInInitializerError: Exception of type 'Java.Lang.ExceptionInInitializerError' was thrown. ---> Android.OS.NetworkOnMainThreadException: Exception of type 'Android.OS.NetworkOnMainThreadException' was thrown.
07-04 23:10:24.571 E/mono-rt (22361):
07-04 23:10:24.571 E/mono-rt (22361): --- End of managed exception stack trace ---
07-04 23:10:24.571 E/mono-rt (22361): android.os.NetworkOnMainThreadException
07-04 23:10:24.571 E/mono-rt (22361): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
07-04 23:10:24.571 E/mono-rt (22361): at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
07-04 23:10:24.571 E/mono-rt (22361): at java.net.InetAddress.getLocalHost(InetAddress.java:396)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.netbios.NbtAddress.<clinit>(NbtAddress.java:187)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.netbios.NbtAddress.getWINSAddress(NbtAddress.java:533)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.UniAddress.<clinit>(UniAddress.java:62)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:864)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.smb.SmbFile.connect(SmbFile.java:951)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.smb.SmbFile.open0(SmbFile.java:972)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.smb.SmbFile.open(SmbFile.java:1006)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:97)
07-04 23:10:24.571 E/mono-rt (22361): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:67)
07-04 23:10:24.571 E/mono-rt (22361): at md5ac18087b2af203d2f41df0f73b22a485.BodyInspectionForm_TabFragment.n_onOptionsItemSelected(Native Method)
07-04 23:10:24.571 E/mono-rt (22361): at md5ac18087b2af203d2f41df0f73b22a485.BodyInspectionForm_TabFragment.onOptionsItemSelected(BodyInspectionForm_TabFragment.java:47)
07-04 23:10:24.571 E/mono-rt (22361): at android.app.Fragment.performOptionsItemSelected(Fragment.java:2159)
07-04 23:10:24.571 E/mono-rt (22361): at android.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:1988)
07-04 23:10:24.571 E/mono-rt (22361): at android.app.Activity.onMenuItemSelected(Activity.java:2970)
07-04 23:10:24.571 E/mono-rt (22361): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1136)
07-04 23:10:24.571 E/mono-rt (22361): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
07-04 23:10:24.571 E/mono-rt (22361): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
07-04 23:10:24.571 E/mono-rt (22361): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
07-04 23:10:24.571 E/mono-rt (22361): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
07-04 23:10:24.571 E/mono-rt (22361): at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:186)
07-04 23:10:24.571 E/mono-rt (22361): at android.widget.AdapterView.performItemClick(AdapterView.java:305)
07-04 23:10:24.571 E/mono-rt (22361): at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
07-04 23:10:24.571 E/mono-rt (22361): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3057)
07-04 23:10:24.571 E/mono-rt (22361): at android.widget.AbsListView$3.run(AbsListView.java:3864)
07-04 23:10:24.571 E/mono-rt (22361): at android.os.Handler.handleCallback(Handler.java:739)
07-04 23:10:24.571 E/mono-rt (22361): at android.os.Handler.dispatchMessage(Handler.java:95)
07-04 23:10:24.571 E/mono-rt (22361): at android.os.Looper.loop(Looper.java:139)
07-04 23:10:24.571 E/mono-rt (22361): at android.app.ActivityThread.main(ActivityThread.java:5298)
07-04 23:10:24.571 E/mono-rt (22361): at java.lang.reflect.Method.invoke(Native Method)
07-04 23:10:24.571 E/mono-rt (22361): at java.lang.reflect.Method.invoke(Method.java:372)
07-04 23:10:24.571 E/mono-rt (22361): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
07-04 23:10:24.571 E/mono-rt (22361): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
07-04 23:10:24.571 E/mono-rt (22361):
07-04 23:10:24.571 E/mono-rt (22361): --- End of inner exception stack trace ---
07-04 23:10:24.571 E/mono-rt (22361): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
07-04 23:10:24.571 E/mono-rt (22361): at Java.Interop.JniEnvironment+Object._NewObject (JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00085] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12200
07-04 23:10:24.571 E/mono-rt (22361): at Java.Interop.JniEnvironment+Object.NewObject (JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0000b] in /Users/builder/data/lanes/3340/4e275588/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.Object.cs:33
07-04 23:10:24.571 E/mono-rt (22361): at Android.Runtime.JNIEnv.NewObject (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/data/lanes/3340/4e275588/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:768
07-04 23:10:24.571 E/mono-rt (22361): at Android.Runtime.JNIEnv.NewObject (IntPtr jclass, IntPtr jmethod, Android.Runtime.JV
我将这些权限添加到我的AndroidManifest.xml
<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"/>
有谁能帮我一下吗?编辑:根据注释更新了代码片段
更改您的:
"127.0.0.1/Desktop-l8s2bi3/c"
到Samba共享服务器的IP地址或主机名:
"MyWindowsPCDesktop/Desktop-l8s2bi3/c"
因为"127.0.0.1"将引用Android设备/模拟器本身。
Re: https://github.com/sushihangover/Xamarin.Android.jCIFS
// This is NOT best-practice code, just showing a demo Jcifs api call
public async Task getFileContents ()
{
await Task.Run (() => {
var smbStream = new SmbFileInputStream ("smb://guest@10.10.10.5/code/test.txt");
byte[] b = new byte[8192];
int n;
while ((n = smbStream.Read (b)) > 0) {
Console.Write (Encoding.UTF8.GetString (b).ToCharArray (), 0, n);
}
Button button = FindViewById<Button> (Resource.Id.myButton);
RunOnUiThread(() => {
button.Text = Encoding.UTF8.GetString (b);
});
}
).ContinueWith ((Task arg) => {
Console.WriteLine (arg.Status);
if (arg.Status == TaskStatus.Faulted)
Console.WriteLine (arg.Exception);
}
);
}