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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:09:05+00:00 2026-06-18T08:09:05+00:00

I have a (rather static) class like: class Test { private Planet gault; private

  • 0

I have a (rather static) class like:

class Test
{
    private Planet gault;
    private Planet irtok;
    private Planet ktaris;

    /* problem:
    private Planet [] planets = {
        this.gault, this.irtok, this.ktaris
    };
    */

    Test() {

    }

    public void doTest() {
        this.gault  = new Planet("Klingon", 1322);
        this.irtok  = new Planet("Ferengi", 1213);
        this.ktaris = new Planet("Ktarian", 16512);
    }
}

What I want (if I can) is to have an array pointing to each planet – .

private Planet [] planets = {
    this.gault, this.irtok, this.ktaris
};

So that I in doTest() can do something like:

for (Planet p: in planets)
    p.printInfo();

From the various ways I’ve tried I always end up with p being NULL;

  • 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-18T08:09:06+00:00Added an answer on June 18, 2026 at 8:09 am

    Your planets are null by default. You only initialize them in the doTest() method. But the line initializing the array of planets is executed long before: when the Test object is constructed. So at this time, all the planets are still null, since doTest() has not been called yet.

    The array should be initialized right after the planets are. And everything should probablybe done in the constructor rather than in doTest().

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

Sidebar

Related Questions

Suppose I have a class like below: public static class Foo { public static
I have a class like: public class Food { public static IList<Ingredient> ingredients public
Let's say I have a factory ressembling this: public static class BusinessObjectFactory { public
Suppose I have the following classes: public class Test { public static void main(String[]
The problem is that I have used my SqlConnection as a public static connection,
I have a class with a static method that looks roughly like: class X
I have around 150 gifs (all rather small = 1KB) in a static class
I have a rather large text corpus, of which I would like to check
I have a class that is declared in my application that has a private
I have this test: (ns opengltuts.core-test (:use clojure.test opengltuts.util) (:import (org.lwjgl.opengl GL11 GL12 GL13

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.