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 9131461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:08:43+00:00 2026-06-17T08:08:43+00:00

I have only been developing Android for two weeks now and have done lots

  • 0

I have only been developing Android for two weeks now and have done lots of googling into this problem I have but can’t seem to get anything to work.

I have a Helper Class which has one method to set up DatePicker Limits etc.

public class AlarmHelper extends Activity {

    public void setupDatePicker(){
        long maxTime = 52560000;
        final Calendar cal = Calendar.getInstance();
        DatePicker dp = (DatePicker)findViewById(R.id.datePicker);
        dp.setMinDate(cal.getTimeInMillis() - 1000);
        dp.setMaxDate(cal.getTimeInMillis() + maxTime);
    }

}

I then try to call the setupDatePicker() from the MainActivity in the onCreate() method like so.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    AlarmHelper helper = new AlarmHelper();
    helper.setupDatePicker();

    setContentView(R.layout.activity_main);
}

When I run the app I get a NullPointerException. I believe it has something to do the the Context but I haven’t got a clue how to implement it within my helper class.

Any help would be greatly appreciated.

  • 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-17T08:08:44+00:00Added an answer on June 17, 2026 at 8:08 am

    currently you are trying to findViewById before setting Activity layout .change your Activity onCreate code as :

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    
           // your code here...
        setContentView(R.layout.activity_main);   //<< set layout for Activity here
    
        AlarmHelper helper = new AlarmHelper(MainActivity.this);
        helper.setupDatePicker();
    
    
    }
    

    and in your AlarmHelper no need to extends Activity class if it’s not an Activity .Change your AlarmHelper class as because to access UI elements from other non Activity class you will need to pass activity context :

    public class AlarmHelper  {
    
    Activity activity;
    
    public AlarmHelper(Activity activity){
      this.activity=activity;
    }
    
        public void setupDatePicker(){
            long maxTime = 52560000;
            final Calendar cal = Calendar.getInstance();
            DatePicker dp = (DatePicker)activity.findViewById(R.id.datePicker);
            dp.setMinDate(cal.getTimeInMillis() - 1000);
            dp.setMaxDate(cal.getTimeInMillis() + maxTime);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using JavaScript as a tool for many years now, but only
I am pretty new to Android and have been developing a game. Every now
I have been developing an Android/Java application that opens up two simultaneous Apache HTTP
I've only just really started android developing and have been reading about services here
Lately I have been thinking about developing some basic android app. Its only due
I've been tasked with maintaining a Visual Studio 2005 solution but I only have
I have been writing Python code for only a couple of weeks, so I'm
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been using echo $.sprintf(%01\$.2f,$numvar); for my USD formatting, but I only copied
I have been developing an Android app and testing with a 1.5 AVD and

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.