[mono-android] Exception in PreferenceManager.GetDefaultSharedPreferences

Steven Pack steven_john_pack at yahoo.com.au
Thu Oct 25 21:10:52 UTC 2012


Hi All,

I'm getting the exception below from some of my testers phones.

It's a call to a static Android method, and I don't actually see an exception message, just a call stack (the logger calls ToString() on the exception). 


My only idea is that I'm using Application.Context  in the call and I've seen/read that that can cause some issues. I'll try that when I get on to my dev PC, but open to any ideas.




2012-10-12 10:58:21.360 E 11853/SplashPresenter: 5 Failed to start
Java.Lang.Throwable: Exception of type 'Java.Lang.Throwable' was thrown.
  at Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in <filename unknown>:0 
  at Android.Preferences.PreferenceManager.GetDefaultSharedPreferences (Android.Content.Context context) [0x00000] in <filename unknown>:0 
  at com.xxx.android.AndroidSettingsProvider.Load () [0x00000] in <filename unknown>:0 
  at xxx.Lib.SplashPresenter.RunStartupTasksAsync (System.Object state) [0x00000] in <filename unknown>:0 
  --- End of managed exception stack trace ---
java.lang.NullPointerException
    at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:371)
    at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:366)
    at dalvik.system.NativeStart.run(Native Method)



void RunStartupTasksAsync (object state)  {  try  {  try  {  _log.Debug (Tag, "Running startup tasks...");  UnpackDb ();  ConnectDb ();  SmokeTestDb ();  _settings.Load();   //Go to search screen  View.InvokeOnGuiThread (() =>  {  View.NavigateToWordSearch ();  });  } catch (Mono.Data.Sqlite.SqliteException ex)  {  _log.Error (Tag, "Db smoke test failed. Will attempt to rebuild...", ex);  _unpacker.Delete (Constants.DATABASE_NAME);  View.InvokeOnGuiThread (() => View.ShowCorruptDatabaseDialog ());  }    } catch (Exception ex)  {  _log.Error (Tag, "Failed to start", ex);  View.InvokeOnGuiThread (() => View.ShowCorruptDatabaseDialog ());  }  }


...

public override void Load()  {  var prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context);   this.Update(Settings.TextSizeKey, prefs.GetString(Settings.TextSizeKey, "16"));  this.Update(Settings.LinkWordsKey, prefs.GetBoolean(Settings.LinkWordsKey, false).ToString());  }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodroid/attachments/20121025/1dc5799e/attachment-0001.html>


More information about the Monodroid mailing list