Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am getting NullPointerException in my Activity as soon as I call the dpd.show() method. #757

Open
vikash-sh opened this issue May 20, 2024 · 0 comments

Comments

@vikash-sh
Copy link

vikash-sh commented May 20, 2024

@wdullaer

My MainActivity class extends a BaseFragmentActivity (Custom) which extends FragmentActivity and I can't change it as changing it disturbs my App's functionality. MainActivity neither includes a ToolBar nor it's hidden in styles.xml for the Custom MainActivity Theme. Now I implemented the library as implementation 'com.wdullaer:materialdatetimepicker:4.2.3' and used the sample code to show DatePickerDialog as below but I am getting an exception which occurs as soon as I click on imageSearch ImageView. Please help me to resolve this issue. Also, I am implementing it in Tablet UI.

build.gradle (:app)

dependencies {
    implementation 'com.wdullaer:materialdatetimepicker:4.2.3'
}

Code:

imageSearch.setOnClickListener(v -> {
            Calendar now = Calendar.getInstance();
            com.wdullaer.materialdatetimepicker.date.DatePickerDialog dpd = com.wdullaer.materialdatetimepicker.date.DatePickerDialog.newInstance(
                    onDateSetListener,
                    now.get(Calendar.YEAR), // Initial year selection
                    now.get(Calendar.MONTH), // Initial month selection
                    now.get(Calendar.DAY_OF_MONTH) // Inital day selection
            );
            // If you're calling this from an AppCompatActivity
            dpd.show(getSupportFragmentManager(), "Datepickerdialog");
        });

    private com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener onDateSetListener = (view, year, monthOfYear, dayOfMonth) -> {
        String date = "You picked the following date: " + dayOfMonth + "/" + (++monthOfYear) + "/" + year;
        Log.e("DatePickerDialog", "onDateSet: selectedDate=> " + date);
    };

Crash:

                                       FATAL EXCEPTION: main
                                       Process: com.noteactivethreebeta, PID: 12716
                                       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:247)
                                       at com.android.internal.app.WindowDecorActionBar.init(WindowDecorActionBar.java:199)
                                       at com.android.internal.app.WindowDecorActionBar.<init>(WindowDecorActionBar.java:181)
                                       at android.app.Dialog.show(Dialog.java:477)
                                       at androidx.fragment.app.DialogFragment.onStart(DialogFragment.java:993)
                                       at androidx.fragment.app.Fragment.performStart(Fragment.java:3187)
                                       at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager.java:628)
                                       at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:290)
                                       at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
                                       at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
                                       at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
                                       at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:565)
                                       at android.os.Handler.handleCallback(Handler.java:942)
                                       at android.os.Handler.dispatchMessage(Handler.java:99)
                                       at android.os.Looper.loopOnce(Looper.java:226)
                                       at android.os.Looper.loop(Looper.java:313)
                                       at android.app.ActivityThread.main(ActivityThread.java:8810)
                                       at java.lang.reflect.Method.invoke(Native Method)
                                       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
@vikash-sh vikash-sh changed the title I am getting NullPointerException in my Activity as soon as I call the show method. I am getting NullPointerException in my Activity as soon as I call the dpd.show() method. May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant