Error / Application Crash on Android

Hi,

I've got the PDFViewer in a Xamarin Forms Project.

Here's the XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" prism:ViewModelLocator.AutowireViewModel="True"
    xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms"
    x:Class="MemberApp.Views.PdfViewer"
    xmlns:syncfusion="clr-namespace:Syncfusion.SfPdfViewer.XForms;assembly=Syncfusion.SfPdfViewer.XForms"
    Title = "{Binding Title}"
    >
    <ContentPage.Content>
        <Grid x:Name="pdfViewGrid" Padding = "0,20,0,0">
            <syncfusion:SfPdfViewer x:Name="pdfViewerControl" InputFileStream="{Binding PdfStream}"/>
        </Grid> 
    </ContentPage.Content>
</ContentPage>

Here's the ViewModel:

public override void OnNavigatedTo(NavigationParameters parameters)
{

    try
    {
        base.OnNavigatedTo(parameters);
        var FileName = (String)parameters["FileName"];

        Title = FileName;

        #if __IOS__
            var resourcePrefix = "MemberApp.iOS";
        #endif
        #if __ANDROID__
            var resourcePrefix = "MemberApp.Droid";
        #endif

        var ResourceName = String.Format("{0}.Files.{1}.pdf", resourcePrefix, FileName);
        PdfStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream(ResourceName);        
    } catch (Exception e) {
        
    }
}

Here's the Error Detail:

[zygote] Waiting for a blocking GC Explicit
[zygote] WaitForGcToComplete blocked for 8.763ms for cause Explicit
[zygote] Explicit concurrent copying GC freed 2445(163KB) AllocSpace objects, 0(0B) LOS objects, 54% free, 1304KB/2MB, paused 544us total 7.101ms
[zygote] JNI RegisterNativeMethods: attempt to register 0 native methods for md5febb1bca8c6f8f7641bd0dd395a93b5b.ImageViewEx
[View] requestLayout() improperly called by md5270abb39e60627f0f200893b490a1ade.NavigationPageRenderer{8e0d8f2 V.E...... ......ID 0,0-1440,2308 #3} during second layout pass: posting in next frame
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.ArgumentOutOfRangeException: The index can't be less then zero or greater then Count.
[MonoDroid] Parameter name: index
[MonoDroid]   at Syncfusion.Pdf.Primitives.PdfArray.get_Item (System.Int32 index) [0x0000d] in <978e4ad3886745c38e0469bf3c61dfb0>:0 
[MonoDroid]   at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection.GetPage (System.Int32 index) [0x00019] in <978e4ad3886745c38e0469bf3c61dfb0>:0 
[MonoDroid]   at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection.get_Item (System.Int32 index) [0x00000] in <978e4ad3886745c38e0469bf3c61dfb0>:0 
[MonoDroid]   at Syncfusion.SfPdfViewer.XForms.Droid.LinearLayoutEx.RenderHyperlink (System.Int32 pageIndex) [0x00046] in <1c589328a0d14df7a16a0c57623edd27>:0 
[MonoDroid]   at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.loadDocumentWorker_RunWorkerCompleted (System.Object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) [0x00147] in <1c589328a0d14df7a16a0c57623edd27>:0 
[MonoDroid]   at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted (System.ComponentModel.RunWorkerCompletedEventArgs e) [0x00019] in <bcdc1df2b3724ab69797f3819a126346>:0 
[MonoDroid]   at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted (System.Object arg) [0x0000e] in <bcdc1df2b3724ab69797f3819a126346>:0 
[MonoDroid]   at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <9e3ea4062ff24a9eb92486d44f624346>:0 
[MonoDroid]   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <9e3ea4062ff24a9eb92486d44f624346>:0 
[MonoDroid]   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9e3ea4062ff24a9eb92486d44f624346>:0 
[MonoDroid]   at (wrapper dynamic-method) System.Object.ef91014f-3aa3-4152-b200-0e85eaa1ea58(intptr,intptr)
[zygote] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
[zygote] Explicit concurrent copying GC freed 1634(187KB) AllocSpace objects, 4(96KB) LOS objects, 53% free, 1323KB/2MB, paused 69us total 4.379ms
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: com.hatzalah.member_app, PID: 12155
[AndroidRuntime] android.runtime.JavaProxyThrowable: System.ArgumentOutOfRangeException: The index can't be less then zero or greater then Count.
[AndroidRuntime] Parameter name: index
[AndroidRuntime]   at Syncfusion.Pdf.Primitives.PdfArray.get_Item (System.Int32 index) [0x0000d] in <978e4ad3886745c38e0469bf3c61dfb0>:0 
[AndroidRuntime]   at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection.GetPage (System.Int32 index) [0x00019] in <978e4ad3886745c38e0469bf3c61dfb0>:0 
[AndroidRuntime]   at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection.get_Item (System.Int32 index) [0x00000] in <978e4ad3886745c38e0469bf3c61dfb0>:0 
[AndroidRuntime]   at Syncfusion.SfPdfViewer.XForms.Droid.LinearLayoutEx.RenderHyperlink (System.Int32 pageIndex) [0x00046] in <1c589328a0d14df7a16a0c57623edd27>:0 
[AndroidRuntime]   at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.loadDocumentWorker_RunWorkerCompleted (System.Object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) [0x00147] in <1c589328a0d14df7a16a0c57623edd27>:0 
[AndroidRuntime]   at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted (System.ComponentModel.RunWorkerCompletedEventArgs e) [0x00019] in <bcdc1df2b3724ab69797f3819a126346>:0 
[AndroidRuntime]   at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted (System.Object arg) [0x0000e] in <bcdc1df2b3724ab69797f3819a126346>:0 
[AndroidRuntime]   at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <9e3ea4062ff24a9eb92486d44f624346>:0 
[AndroidRuntime]   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <9e3ea4062ff24a9eb92486d44f624346>:0 
[AndroidRuntime]   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9e3ea4062ff24a9eb92486d44f624346>:0 
[AndroidRuntime]   at (wrapper dynamic-method) System.Object.ef91014f-3aa3-4152-b200-0e85eaa1ea58(intptr,intptr)
[AndroidRuntime] at mono.java.lang.RunnableImplementor.n_run(Native Method)
[AndroidRuntime] at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
[AndroidRuntime] at android.os.Handler.handleCallback(Handler.java:789)
[AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:98)
[AndroidRuntime] at android.os.Looper.loop(Looper.java:164)
[AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:6541)
[AndroidRuntime] at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
[AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
[zygote] Explicit concurrent copying GC freed 360(110KB) AllocSpace objects, 0(0B) LOS objects, 53% free, 1324KB/2MB, paused 88us total 7.562ms


2 Replies

DA Danny Ackerman March 13, 2018 12:07 AM UTC

Hmm.  I just renamed the folder containing my PDF files in my Shared project from Files to Assets, and now it seems like everything is working.

Does the folder with the PDF files need to be named Assets for Android to work properly?


NK Navaneetha Kannan Sudalai Muthu Syncfusion Team March 13, 2018 10:00 AM UTC

Hi Danny, 

We are glad that your issue has been resolved. In the code snippet you have provided, we could see that you are loading the PDF document as stream in the PDF viewer, in that case the folder name does not bother working of PDF viewer. Hope it might be some problem with the project. For you reference we have provided the sample in which the PDF document is loaded from the Files folder, in the link below. 


We confirm that we can reproduce the exception you have stated, when loading a single page PDF document in the PDF viewer for Android, the fix for the issue will be available in our upcoming service pack release 2018 volume 1 SP1, which is scheduled in the end of March 2018.  

Further, we have created a Direct-Trac incident under your account and we have delivered the fix for this issue there. 

Please let us know if you need any further assistance. 

Best, 
Navaneetha Kannan 


Loader.
Up arrow icon