Object reference not set to an instance of an object while initializing WebView Xamarin Android -


i have following code:-

protected override void oncreate(bundle bundle) {     base.oncreate(bundle);     setcontentview(resource.layout.layoutinformation);      webview body = findviewbyid<webview>(resource.id.bodycontentwv);-- error here      // create application here } 

layoutinformation.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:minwidth="25px"     android:minheight="25px">      <android.webkit.webview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/bodycontentwv" />  </linearlayout> 

i following error while initializing webview. can point out iam doing wrong?

system.nullreferenceexception: object reference not set instance of object 

ok, try show on code, in 3 points:

1) have class named: extendedwebviewclient. looks this:

public class extendedwebviewclient : webviewclient {     public override bool shouldoverrideurlloading(webview view, string url)     {         view.loadurl(url);         return true;     } } 

2) have activity named searchwebactivity. has resource xml file , .cs file.

a) resource xml file:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minwidth="25px" android:minheight="25px"> <webview     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/searchweb_webview" /> 

b) class .cs file searchwebactivity:

public class searchwebactivity: activity {     webview _searchweb_webview;     protected override void oncreate(bundle bundle)     {         base.oncreate(bundle);          setcontentview(resource.layout.searchwebactivity);         _searchweb_webview= findviewbyid<webview>(resource.id.searchweb_webview);          setwebview();     }      private void setwebview()     {         _searchweb_webview.settings.loadwithoverviewmode = true;         _searchweb_webview.settings.usewideviewport = true;         _searchweb_webview.settings.builtinzoomcontrols = true;         _searchweb_webview.settings.javascriptenabled = true;         _searchweb_webview.scrollbarfadingenabled = false;         _searchweb_webview.setinitialscale(1);         _searchweb_webview.setwebviewclient(new extendedwebviewclient());          _searchweb_webview.loadurl("www.google.com");     } } 

hope help.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -