Android Spinner dialog popup not working after update from sdk 28 to sdk29

  android, android-spinner, androidx, dialog

I have a App with a popup dialog spinner that used to work on SDK 28 without problems.
Now i have migrated to SDK 29 AndroidX and the popup does not work anymore.

Spinner_LockSetting = (Spinner) findViewById(R.id.Spinner_LockSetting);
SettingValueAdapter adapter = new SettingValueAdapter(this, android.R.layout.simple_spinner_dropdown_item, SettingValue.values());
Spinner_LockSetting.setAdapter(adapter);

        Spinner_LockSetting.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                                       int arg2, long arg3) {
                   // do something
                }
            }
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });

Layout XML

<Spinner
     android:id="@+id/Spinner_LockSetting"
     android:layout_width="100dp"
     android:layout_height="50dp"
     android:prompt="@string/app_name"
     android:spinnerMode="dialog" />

When i click on the spinner i get this exception:

    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
        at com.android.internal.app.WindowDecorActionBar.getDecorToolbar(WindowDecorActionBar.java:251)
        at com.android.internal.app.WindowDecorActionBar.init(WindowDecorActionBar.java:196)
        at com.android.internal.app.WindowDecorActionBar.<init>(WindowDecorActionBar.java:180)
        at android.app.Dialog.show(Dialog.java:437)
        at androidx.appcompat.widget.AppCompatSpinner$DialogPopup.show(AppCompatSpinner.java:908)
        at androidx.appcompat.widget.AppCompatSpinner.showPopup(AppCompatSpinner.java:608)
        at androidx.appcompat.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:452)
        at android.view.View.performClickInternal(View.java:8137)
        at android.view.View.access$3700(View.java:888)
        at android.view.View$PerformClick.run(View.java:30250)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8425)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

When i set the spinnermode XML to dropdown it works without problems.
I don’t know where the NullPointerException is referring to, do i need to do more with dialogs in AndroidX vs SDK28?

Source: Android Questions

LEAVE A COMMENT