We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Error when building on Android device

Hello, I'm working with DOCIO and when I build and save the file in IOS with this method it works perfectly:
                //Save the stream as a file in the device and invoke it for viewing
                await Xamarin.Forms.DependencyService.Get<ISave>().SaveAndView(documentName + ".docx", "application/msword", stream);



However when I try to save the document in android the app crashes and I get this error:

Java.IO.FileNotFoundException: /storage/emulated/0/Syncfusion/x.docx (No such file or directory)
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <09821b4f44794452b7d6c054ac9447f5>:0
  at Java.Interop.JniPeerMembers+JniInstanceMethods.FinishCreateInstance (System.String constructorSignature, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0004f] in <09821b4f44794452b7d6c054ac9447f5>:0
  at Java.IO.FileOutputStream..ctor (Java.IO.File file) [0x0007a] in <788a34f7a7b84486905dfde786529d42>:0
  at SaveAndroid.SaveAndView (System.String fileName, System.String contentType, System.IO.MemoryStream stream) [0x00091] in /Users/helpdesk/Desktop/expandingList/expandingList.Android/SaveAndroid.cs:36
  at expandingList.MainPage.Handle_Clicked (System.Object sender, System.EventArgs e) [0x02657] in /Users/helpdesk/Desktop/expandingList/expandingList/MainPage.xaml.cs:551
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <58604b4522f748968296166e317b04b4>:0
  at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <788a34f7a7b84486905dfde786529d42>:0
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <788a34f7a7b84486905dfde786529d42>:0
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <788a34f7a7b84486905dfde786529d42>:0
  at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.62(intptr,intptr)
  at java.io.FileNotFoundException: /storage/emulated/0/Syncfusion/x.docx (No such file or directory)
  at at java.io.FileOutputStream.open0(Native Method)
  at at java.io.FileOutputStream.open(FileOutputStream.java:287)
  at at java.io.FileOutputStream.<init>(FileOutputStream.java:223)
  at at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
  at at md58432a647068b097f9637064b8985a5e0.ButtonRenderer.n_onClick(Native Method)
  at at md58432a647068b097f9637064b8985a5e0.ButtonRenderer.onClick(ButtonRenderer.java:76)
  at at android.view.View.performClick(View.java:6294)
  at at android.view.View$PerformClick.run(View.java:24770)
  at at android.os.Handler.handleCallback(Handler.java:790)
  at at android.os.Handler.dispatchMessage(Handler.java:99)
  at at android.os.Looper.loop(Looper.java:164)
  at at android.app.ActivityThread.main(ActivityThread.java:6494)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)



Any help on this would be greatly appreciated. 

Thanks
Mason


3 Replies

MJ Mohanaselvam Jothi Syncfusion Team May 10, 2019 11:41 AM UTC

Hi Mason,

Thank you for contacting Syncfusion support.

Please refer our below documentation to create Word document in Xamarin.Forms using DocIO and kindly try the sample to achieve your requirement:
https://www.syncfusion.com/kb/10022/how-to-create-word-document-in-xamarin
Sample to create Word document

If you are still facing the same problem means, then kindly share us the below details from your end:
  1. Share us the modified sample of above along with complete code snippet.
  2. Android version of the device which used at your end.
  3. Please confirm us whether storage permission of this app in your device is enabled. If not, then kindly enable the storage permission once the application is deployed to access the storage location.

Based on the above details, we will check the reported problem in similar target android version and will provide you the appropriate solution at the earliest.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



MM Mason Merrell May 14, 2019 09:28 PM UTC

Hello,

Thank you for your support on this matter. The storage permissions were the problem with saving the file to the device. However, the file viewer doesn't invoke like it does for IOS I only get this warning: "Warning CS0618: 'Forms.Context' is obsolete: 'Context is obsolete as of version 2.5. Please use a local context instead.' (CS0618)." Would this be the reason the viewer doesn't appear and is there anything I can do to resolve this? 

Thanks in advance!
Mason 


MJ Mohanaselvam Jothi Syncfusion Team May 15, 2019 12:25 PM UTC

Hi Mason,

Thank you for your update.

We have tried to reproduce the reported problem
(file viewer doesn't invoke) by deploying the sample application (from KB documentation) in Android device, but it opens the Word document properly at our end. We suspect that the problem might be due to the device or Android version specific. So, could you please share us the details about Android version of the device which tried at your end. Thereby, we will try to reproduce the problem and will update you the solution at the earliest.

Regards,
Mohanaselvam J
 


Loader.
Live Chat Icon For mobile
Up arrow icon