I am using a custom renderer for showing a pdf file on my app.
Below are my renderer codes:
Main Project:
public class PdfWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(PdfWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
Android:
[assembly: ExportRenderer(typeof(PdfWebView), typeof(MyWebViewRenderer))]
namespace Projectname.Droid.Renderer
{
public class MyWebViewRenderer : WebViewRenderer
{
public MyWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var customWebView = Element as PdfWebView;
Control.Settings.AllowUniversalAccessFromFileURLs = true;
Control.Settings.JavaScriptEnabled = true;
Control.LoadUrl(string.Format("https://drive.google.com/viewerng/viewer?url={0}", customWebView.Uri.ToString()));
}
}
}
}
Xaml and Xaml.cs:
<local:PdfWebView
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
x:Name="pdf_Webview"/>
pdf_Webview.Source = pdfurl;
pdf_Webview.Uri = pdfurl;
But when I run the app on the android platform getting the below exception:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
No Renderers are using on the ios part and pdf is working fine on there. What is the actual issue on the android part?