Adding widget provider causes crash at startup

TheLearnerTheLearner CXMember ✭✭
edited August 2017 in Xamarin.Android

Hi,

Im trying to add a widget to my app in android.
The app works fine, until i add the two files for the widget which causes a crash at startup.
Even when it crashes, i am still able to grab the widget to home screen and it loads the layout correctly, just the main page crashes me at startup.
Tested on Android 4.4 KitKat VM, Visual Studio editor.

File #1 "/xml/status_widget.xml"

<?xml version="1.0" encoding="utf-8"?>

    <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
        android:minWidth="294dip"
        android:minHeight="72dip"
        android:updatePeriodMillis="86400000"
        android:initialLayout="@layout/status_widget"
        android:widgetCategory="home_screen">
    </appwidget-provider>

File #2 "/layout/status_widget.axml"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dip"
        android:padding="10dip"
        android:gravity="center"
        android:text="@string/widget_loading" />
</LinearLayout>

Crashes at file MainActivity.cs at "base.OnCreate (bundle);" for Java.Lang.NullPointerException

using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Server_Monitor.Droid
{
    [Activity (Label = "Server_Monitor", Icon = "@drawable/icon", Theme="@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate (Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar; 

            base.OnCreate (bundle); // Crashes here complaining bundle is null / 'Java.Lang.NullPointerException'

            global::Xamarin.Forms.Forms.Init (this, bundle);
            LoadApplication (new Server_Monitor.App ());
        }
    }
}
Tagged:

Answers

Sign In or Register to comment.