1
Vote

NullPointerException when using DialogService provided by the lib

description

I am building an Android app using Xamarin and mvvm-light and I am using DialogService provided by mvvmlight....When I click the button bound to the following command I get an exception.
private RelayCommand _getEventsCommand;

public RelayCommand GetEventsCommand
{
    get
    {
        return _getEventsCommand
            ?? (_getEventsCommand = new RelayCommand(() => _dialogService.ShowMessage("sample alert message", "Sample alert title")));
    }
}
And the exception:
03-17 17:20:59.850 E/mono    (16027): Unhandled Exception:
03-17 17:20:59.850 E/mono    (16027): Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
03-17 17:20:59.850 E/mono    (16027):   --- End of managed Java.Lang.NullPointerException stack trace ---
03-17 17:20:59.850 E/mono    (16027): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
03-17 17:20:59.850 E/mono    (16027):   at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:222)
03-17 17:20:59.850 E/mono    (16027):   at android.app.AlertDialog$Builder.<init>(AlertDialog.java:452)
03-17 17:20:59.850 E/mono    (16027):   at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
03-17 17:20:59.850 E/mono    (16027):   at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)
03-17 17:20:59.850 E/mono    (16027):   at android.view.View.performClick(View.java:5204)
03-17 17:20:59.850 E/mono    (16027):   at android.view.View$PerformClick.run(View.java:21153)
03-17 17:20:59.850 E/mono    (16027):   at android.os.Handler.handleCallback(Handler.java:739)
03-17 17:20:59.850 E/mono    (16027):   at android.os.Handler.dispatchMessage(Handler.java:95)
03-17 17:20:59.850 E/mono    (16027):   at android.os.Looper.loop(Looper.java:148)
03-17 17:20:59.850 E/mono    (16027):   at android.app.ActivityThread.main(ActivityThread.java:5417)
03-17 17:20:59.850 E/mono    (16027):   at java.lang.reflect.Method.invoke(Native Method)
03-17 17:20:59.850 E/mono    (16027):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-17 17:20:59.850 E/mono    (16027):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-17 17:20:59.850 E/mono    (16027): 
__03-17 17:20:59.850 E/mono-rt (16027): [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
__03-17 17:20:59.850 E/mono-rt (16027):   --- End of managed Java.Lang.NullPointerException stack trace ---
03-17 17:20:59.850 E/mono-rt (16027): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
03-17 17:20:59.850 E/mono-rt (16027):   at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:222)
03-17 17:20:59.850 E/mono-rt (16027):   at android.app.AlertDialog$Builder.<init>(AlertDialog.java:452)
03-17 17:20:59.850 E/mono-rt (16027):   at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
03-17 17:20:59.850 E/mono-rt (16027):   at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)
03-17 17:20:59.850 E/mono-rt (16027):   at android.view.View.performClick(View.java:5204)
03-17 17:20:59.850 E/mono-rt (16027):   at android.view.View$PerformClick.run(View.java:21153)
03-17 17:20:59.850 E/mono-rt (16027):   at android.os.Handler.handleCallback(Handler.java:739)
03-17 17:20:59.850 E/mono-rt (16027):   at android.os.Handler.dispatchMessage(Handler.java:95)
03-17 17:20:59.850 E/mono-rt (16027):   at android.os.Looper.loop(Looper.java:148)
03-17 17:20:59.850 E/mono-rt (16027):   at android.app.ActivityThread.main(ActivityThread.java:5417)
03-17 17:20:59.850 E/mono-rt (16027):   at java.lang.reflect.Method.invoke(Native Method)
03-17 17:20:59.850 E/mono-rt (16027):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-17 17:20:59.850 E/mono-rt (16027):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Am I doing something wrong or it's a bug somewhere in the lib?

comments

mbob wrote Mar 23 at 2:08 PM

Just made a test: I have copy-pasted the implementation of DialogService from mvvm light into my project and I don't get this exception anymore. Everything works fine.