0

So I have made a web based app in VS2016 using Xamarin.Android and when i load the app. Can someone tell me where i have messed up here? The aim is to open the web page in the app and not go to an external browser.

MainActivity.cs

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Webkit;

namespace ArasiaWebBasedAppFinal
{
    [Activity(Label = "Arasia", MainLauncher = true, Theme = "@android:style/Theme.NoTitleBar")]
    public class MainActivity : Activity
    {
        WebView web_view;
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            web_view.SetWebViewClient (new ArasiaClient());

            SetContentView(Resource.Layout.Main);

            web_view = FindViewById<WebView> (Resource.Id.webview);
            web_view.Settings.JavaScriptEnabled = true;
            web_view.LoadUrl ("http://www.google.com"); 
        }
    }
    public class ArasiaClient : WebViewClient
    {
        public override bool ShouldOverrideUrlLoading (WebView view, string url)
        {
            view.LoadUrl (url);
            return true;
        }
    }
}

Main.axml

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
  • You're calling `web_view.SetWebViewClient()` before you assign anything to `web_view`. Take a look at your stack trace and you should find that it points you to that line and a [NullReferenceException](https://stackoverflow.com/q/4660142/390989). – eldarerathis May 23 '17 at 19:37
  • and in english ? – Aaron Duce May 24 '17 at 06:36

0 Answers0