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

  • Home
  • SEARCH
  • 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 8736579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:20:07+00:00 2026-06-13T10:20:07+00:00

This is my code @Override public void onClick(View v) { final AlertDialog.Builder adb =

  • 0

This is my code

@Override
public void onClick(View v) {
final AlertDialog.Builder adb = new AlertDialog.Builder(getApplicationContext());
adb.setView(LayoutInflater.from(getApplicationContext()).inflate(R.layout.custom, null));

adb.setPositiveButton("Add",new android.content.DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int arg1) {

                DatePicker datePicker = (DatePicker)findViewById(R.id.datePicker);

                java.util.Date date = null;
                Calendar cal = GregorianCalendar.getInstance();
                cal.set(datePicker.getYear(),datePicker.getMonth(), datePicker.getDayOfMonth());
                date = cal.getTime();
            }                  
        });             
adb.show();
}

I have the NullPointerException in this line, and I think datePicker wasn’t findById, because I use AlertDialog.Builder.

cal.set(datePicker.getYear(),datePicker.getMonth(), datePicker.getDayOfMonth());

I tried use adb.findViewById(); but it’is a mistake (The method findViewById(int) is undefined for the type AlertDialog.Builder).
Can you help me, please?

  • 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-06-13T10:20:08+00:00Added an answer on June 13, 2026 at 10:20 am

    Change

    DatePicker datePicker = (DatePicker)findViewById(R.id.datePicker);
    

    this line to

    DatePicker datePicker = (DatePicker)adb.findViewById(R.id.datePicker);
    

    ……………

    try this one:

    final AlertDialog.Builder adb = new AlertDialog.Builder(this);
    final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.main1, null);
    adb.setView(view);
    final Dialog dialog;
    adb.setPositiveButton("Add",new android.content.DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int arg1) {
    
            DatePicker datePicker = (DatePicker)view.findViewById(R.id.datePicker1);
    
            java.util.Date date = null;
            Calendar cal = GregorianCalendar.getInstance();
            cal.set(datePicker.getYear(),datePicker.getMonth(), datePicker.getDayOfMonth());
            date = cal.getTime();
        }                  
    });   
    dialog = adb.create();
    dialog.show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { GLES20.glClearColor(0, 0,
In facebook tutorials I see this sample code: @Override public void onActivityResult(int requestCode, int
Is it possible to change this code: @Override public boolean onKeyDown(int keyCode, KeyEvent event)
i found this code: protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource hwndSource =
I have onPause in activity and works great. This is code @Override protected void
I have this code running in my onDestroy function: @Override protected void onDestroy() {
In this code (from the WCF REST starterkit - preview2): protected override SampleItem OnAddItem(SampleItem
This is my code. I want to override the Draw method import wx.grid as
Here is my code: public class TasksList extends ListActivity { ... private static final
I am using this simple code public class Main extends Activity { private ProgressDialog

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.