Android Question Null Object reference Error in Material Design Preferences Library Example

bobh

New Member
Licensed User
Longtime User
I'm getting an error with Corwin42's Material Design Preferences library/demo

https://www.b4x.com/android/forum/threads/preferences-material-design-preferences.75482/

First want to say this Material Design Preferences Library is very nice!
I am getting an error when rotating phone from Portrait to Landscape using your PreferencesExample1_10 (with Library 1.12).
(I do have your latest appcompat installed and working)

Steps to reproduce:
1. Open the demo app
2. Click menu, settings (portrait shows the preferences correctly and looks fine)
3. Rotate screen (from portrait to landscape). This is where the error occurs (my phone says "Preference Example has stopped", with option to restart)
(I can rotate screen without showing preferences and that works correctly as well)

The issue appears to be a null object reference:
B4X:
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.amberhome.preferenceexample/de.amberhome.preferenceexample.prefs1}: java.lang.NullPointerException: Attempt to read from field 'android.content.Context anywheresoftware.b4a.BA.context' on a null object reference
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4974)
  at android.app.ActivityThread.-wrap21(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:154)
  at android.app.ActivityThread.main(ActivityThread.java:6688)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException: Attempt to read from field 'android.content.Context anywheresoftware.b4a.BA.context' on a null object reference
  at de.amberhome.preferences.PreferenceViewWrapper$MyPreferenceFragment.onCreatePreferences2(PreferenceViewWrapper.java:253)
  at android.support.v7.preference.XpPreferenceFragment.onCreatePreferences(XpPreferenceFragment.java:54)
  at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:223)
  at android.support.v4.app.Fragment.performCreate(Fragment.java:2180)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1244)
  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
  at android.support.v4.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:2893)
  at android.support.v4.app.FragmentController.dispatchCreate(FragmentController.java:190)
  at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:353)
  at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)
  at de.amberhome.preferenceexample.prefs1.onCreate(prefs1.java:33)
  at android.app.Activity.performCreate(Activity.java:6912)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900)
  ... 10 more
 
Last edited:
Top