Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6698283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:33:35+00:00 2026-05-26T06:33:35+00:00

I am trying to show a custom Dialog whenever a button is pressed in

  • 0

I am trying to show a custom Dialog whenever a button is pressed in a specific view. However, I get force close error whenever I try to switch to the view containing the button. LogCat is giving me a NullPointerException on the method that I am using to set the listener, however, I am not sure whey there is an error. I think it may be the Dialog code, but I have written it to Android Developers site’s specs.

Here is the method with the button listener:

//Registers the listeners for the various buttons in the edit view
private void registerButtonListenersAndSetDefaultText() { 

    mTimeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(TIME_PICKER_DIALOG);
        }
    });
    updateTimeButtonText();

    mDayButton.setOnClickListener(new View.OnClickListener() { //here is where
                                                                       //the error is 
                                                                      //being thrown.

        public void onClick(View v) {
            showDialog(DAY_CHECKBOX_DIALOG);
        }
    }); 
    }

Here is the onCreateDialog() method:

@Override
protected Dialog onCreateDialog(int id) { 
    Dialog dialog = new Dialog(this);
    switch(id) { 
    case TIME_PICKER_DIALOG:
        showTimePicker();
    case DAY_CHECKBOX_DIALOG:
        showDayPicker();

    }
    return onCreateDialog(id);
}

Here is the showDayPicker() method (the one I think may be causing the issue):

private Dialog showDayPicker() {
    Dialog dialog = new Dialog(ScheduleEditActivity.this);
    dialog.setContentView(R.layout.day_picker_dialog);
    dialog.setTitle("Choose A Day");
    return dialog;
}

And here is the LogCat:

    10-19 20:23:57.191: ERROR/AndroidRuntime(293): FATAL EXCEPTION: main
    10-19 20:23:57.191: ERROR/AndroidRuntime(293): java.lang.RuntimeException: Unable to start activity ComponentInfo{vt.nhw.android.easyringertoggle/vt.nhw.android.easyringertoggle.ScheduleEditActivity}: java.lang.NullPointerException
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.os.Handler.dispatchMessage(Handler.java:99)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.os.Looper.loop(Looper.java:123)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at java.lang.reflect.Method.invokeNative(Native Method)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at java.lang.reflect.Method.invoke(Method.java:521)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at dalvik.system.NativeStart.main(Native Method)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293): Caused by: java.lang.NullPointerException
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at vt.nhw.android.easyringertoggle.ScheduleEditActivity.registerButtonListenersAndSetDefaultText(ScheduleEditActivity.java:52)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at vt.nhw.android.easyringertoggle.ScheduleEditActivity.onCreate(ScheduleEditActivity.java:39)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    10-19 20:23:57.191: ERROR/AndroidRuntime(293):     ... 11 more

P.S. I have posted this question before, but the actual question body got convoluted so I deleted and reposted. Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:33:36+00:00Added an answer on May 26, 2026 at 6:33 am

    How are you getting your reference to these objects? something like this?

    mTimeButton = (Button)findViewById(R.id.timeBtn);
    

    If so when are you doing that? If the view is not on the screen at the time you make the findViewById() call it is going to return null to you.

    Post your onCreate method and it’ll be easier to figure out what is going on.

    Edit: Also add a comment to the line that the exception is being thrown on. Since we can’t tell which one is 52.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the custom dialog to close on button press //set
I'm trying to make a custom dialog to show a view in this dialog.
Am trying to show a popup dialog or custom view on clicking of the
I'm trying to use pyqt to show a custom QDialog window when a button
I'm trying to show custom error messages without the attribute name in front. I
I am trying to show a progress dialog from a custom dialog while an
Am trying to get the back button in my dialog to go back to
I'm trying to show a custom hint in a TWinControl but I can't figure
I am trying to show my colleagues in my custom webpart. So I adding
Trying to set up a gridview with a custom adapter, I get my cursor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.