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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:46:36+00:00 2026-06-03T15:46:36+00:00

Simplified: Two classes. X and Y. Y extends X. In X I call: Y

  • 0

Simplified:
Two classes. X and Y.

Y extends X.

In X I call:

    Y periodic;

Then in X I call one of Y’s functions:

periodic.conditionDepreciate();

The actual function block in Y is:

    public void conditionDepreciate() {
    ActionListener conditionDepreciation = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
              if (ameba.health > 0) {
                  ameba.health -= 1;
              }
        }
    };
        new Timer(conditionDelayCount * 1000, conditionDepreciation).start();
}

But regardless of what the function does I get an error coming from the X file saying:

Exception in thread “main” java.lang.NullPointerException
at X.(X.java:71)
at X.main(X.java:245)

Line 71 is referring to when I call:

periodic.conditionDepreciate();

Could someone help explain the error?

EDIT:

I want X to call various functions of Y. Which are all, basically, periodic event timers.

I originally had the timers in the X class file but to help with readability I moved into its own class file.

I’m not sure what something like this needs to be initialized with… Y extends X so it should get all its values from X? (I think…)

I posted one of the timer functions above – do I need to tell the Y class file what ameba.health is? or ? I guess I’ll just have to look up functions and classes >.>

  • 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-03T15:46:38+00:00Added an answer on June 3, 2026 at 3:46 pm

    Presumably the value of periodic is null. That’s the default for static/instance fields. You need to assign a non-null reference to it before you can call a method via it. We don’t have enough information about what the value of periodic should be – whether you ought to be creating a new instance somewhere, or using an existing one – but calling a method on a null reference will give a NullPointerException…

    If you tell us more about which instance you expected the method to be called on, we may be able to help further.

    Note that the fact that Y extends X is irrelevant here.

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

Sidebar

Related Questions

First, a little background (greatly simplified): I have two classes, one called Entity and
I have two classes like this (simplified and renamed): class Base { public: virtual
Having the following classes (highly simplified): public class Child { public string Label; public
In a Javascript program I have an object with the following two (simplified) functions:
I have two tables: invoice and charges, with a one-to-many relationship. (simplified) invoice has:
I have two data structure classes (this is a simplified version of my code)
In a simplified situation like this one, with 3 classes: class ClassONE{ protected List<IntermediatedClass>;
I'm overriding a protected function in a subclass. Let's say I have two classes,
I have two ActiveRecord classes. A simplified view of these classes: class Account <
I have written two jQuery functions, the simplified version of which run thus: $('button.class').not('.selected').on('click',

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.