Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Calling Calendar object from another class throws NullPointerException

I want to assign Calendar or Date object which is a global variable in another class. In class Class1 I initialize date object like his:

Calendar date1;
date1 = Calendar.getInstance();

In Class2 I do this:

Calendar date2 = Class1.date1;

Why does it work good if I assign Class1.date1 to date2 inside any method in Class2 but doesn't work if I declare date2 as global variable and assign value Class1.date1? (In this case there will be NullPointerException thrown.)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You simply can't update a global variable without static with another anytype variable because global variables are also class instances and they have to be static to save all the changes that you done on them.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!