Enum variable is found to be null when not set that wayWhen and how should I use a ThreadLocal variable?Wrong ordering in generated table in jpaHow to determine if variable is 'undefined' or 'null'?League Table order pointsBest way to create enum of strings?How to set enum to nullIs there a standard function to check for null, undefined, or blank variables in JavaScript?OGNL setValue target is nullWhat is an idiomatic way of representing enums in Go?Method override returns null
How can "life" insurance prevent the cheapening of death?
What happens to gadgets of players that leave a match
Methods and Feasibility of Antimatter Mining?
How would a village use its river that it shares with another village downstream?
Are programming languages necessary/useful for operations research practitioner?
Can board a plane to Cameroon without a Cameroonian visa?
Two different colors in an Illustrator stroke / line
Do any aircraft carry boats?
SCOTUS - Can Congress overrule Marbury v. Madison by statute?
What is negative current?
How to create a list of dictionaries from a dictionary with lists of different lengths
How does instantaneous velocity or acceleration have any other numerical value than 0?
What is this grasshopper doing?
Does the mana ability restriction of Pithing Needle refer to the cost or the effect of an activated ability?
2.5 year old daughter refuses to take medicine
What is this sticking out of my wall?
Have there been any countries that voted themselves out of existence?
How can I fix a framing mistake so I can drywall?
Are personality traits, ideals, bonds, and flaws required?
How to progress with CPLEX/Gurobi
Is there a basic list of ways in which a low-level Rogue can get advantage for sneak attack?
Why are walk-ins for Global Entry interview typically only accepted when arriving from an international flight?
Could the government trigger by-elections to regain a majority?
How should we understand "unobscured by flying friends" in this context?
Enum variable is found to be null when not set that way
When and how should I use a ThreadLocal variable?Wrong ordering in generated table in jpaHow to determine if variable is 'undefined' or 'null'?League Table order pointsBest way to create enum of strings?How to set enum to nullIs there a standard function to check for null, undefined, or blank variables in JavaScript?OGNL setValue target is nullWhat is an idiomatic way of representing enums in Go?Method override returns null
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Whenever I try to get a field from an enum, it always returns null.
I've set the value of it according to the enum constructor. It still comes out null.
public enum TeamType {
RED("Red",ChatColor.RED,DyeColor.RED,Point.RED),
BLUE("Blue",ChatColor.BLUE,DyeColor.BLUE,Point.BLUE); //<----Set as Point.RED/BLUE
private String name;
private int crystalHealth = 50;
private Point point;
private int teamPoints;
private ChatColor chatColor;
private DyeColor dye;
private HashSet<ArenaPlayer> playerList = new HashSet<>();
private List<ArenaPlayer> queue = new ArrayList<ArenaPlayer>();
private Location spawn;
public Point getPoint()
if(point == null)
System.out.println("WHY? for: " + this.toString()); //<---This always runs
return point;
private TeamType(String name,ChatColor color,DyeColor dye,Point point1)
this.name = name;
this.point = point1; // <--- My assignment
this.dye = dye;
this.chatColor = color;
The Point enum class
public enum Point{
RED(ChatColor.RED + "Red",TeamType.RED),
BLUE(ChatColor.BLUE + "Blue",TeamType.BLUE),
NEUTRAL(ChatColor.WHITE +"None",null);
private String name;
private TeamType teamOwned;
private Point(String name,TeamType team)
this.name = name;
teamOwned = team;
public TeamType getTeamOwned()
return teamOwned;
public String getName()
return name;
@Override
public String toString()
return name;
There's obviously something that's happening outside of my knowledge of Java.
Could it possibly be that the Point Enum is not initialized yet when TeamType enum is. This could explain why it's null.
I need some help.
java enums null
|
show 1 more comment
Whenever I try to get a field from an enum, it always returns null.
I've set the value of it according to the enum constructor. It still comes out null.
public enum TeamType {
RED("Red",ChatColor.RED,DyeColor.RED,Point.RED),
BLUE("Blue",ChatColor.BLUE,DyeColor.BLUE,Point.BLUE); //<----Set as Point.RED/BLUE
private String name;
private int crystalHealth = 50;
private Point point;
private int teamPoints;
private ChatColor chatColor;
private DyeColor dye;
private HashSet<ArenaPlayer> playerList = new HashSet<>();
private List<ArenaPlayer> queue = new ArrayList<ArenaPlayer>();
private Location spawn;
public Point getPoint()
if(point == null)
System.out.println("WHY? for: " + this.toString()); //<---This always runs
return point;
private TeamType(String name,ChatColor color,DyeColor dye,Point point1)
this.name = name;
this.point = point1; // <--- My assignment
this.dye = dye;
this.chatColor = color;
The Point enum class
public enum Point{
RED(ChatColor.RED + "Red",TeamType.RED),
BLUE(ChatColor.BLUE + "Blue",TeamType.BLUE),
NEUTRAL(ChatColor.WHITE +"None",null);
private String name;
private TeamType teamOwned;
private Point(String name,TeamType team)
this.name = name;
teamOwned = team;
public TeamType getTeamOwned()
return teamOwned;
public String getName()
return name;
@Override
public String toString()
return name;
There's obviously something that's happening outside of my knowledge of Java.
Could it possibly be that the Point Enum is not initialized yet when TeamType enum is. This could explain why it's null.
I need some help.
java enums null
You have not initialised the fieldpoint, so no surprise.
– Jagger
Mar 28 at 8:04
pointis initialized in the constructor? @Jagger
– Artish1
Mar 28 at 8:05
2
Can you show the code ofPointclass/enum? The code here seems fine, hence I suspectPoint.BLUEitself might be pointing tonull
– Pushpesh Kumar Rajwanshi
Mar 28 at 8:09
@PushpeshKumarRajwanshi Sure! I edited to add thePointenum class
– Artish1
Mar 28 at 8:12
2
You seem to have some circular dependency leading tonullYou might want to get rid of that.
– Pushpesh Kumar Rajwanshi
Mar 28 at 8:16
|
show 1 more comment
Whenever I try to get a field from an enum, it always returns null.
I've set the value of it according to the enum constructor. It still comes out null.
public enum TeamType {
RED("Red",ChatColor.RED,DyeColor.RED,Point.RED),
BLUE("Blue",ChatColor.BLUE,DyeColor.BLUE,Point.BLUE); //<----Set as Point.RED/BLUE
private String name;
private int crystalHealth = 50;
private Point point;
private int teamPoints;
private ChatColor chatColor;
private DyeColor dye;
private HashSet<ArenaPlayer> playerList = new HashSet<>();
private List<ArenaPlayer> queue = new ArrayList<ArenaPlayer>();
private Location spawn;
public Point getPoint()
if(point == null)
System.out.println("WHY? for: " + this.toString()); //<---This always runs
return point;
private TeamType(String name,ChatColor color,DyeColor dye,Point point1)
this.name = name;
this.point = point1; // <--- My assignment
this.dye = dye;
this.chatColor = color;
The Point enum class
public enum Point{
RED(ChatColor.RED + "Red",TeamType.RED),
BLUE(ChatColor.BLUE + "Blue",TeamType.BLUE),
NEUTRAL(ChatColor.WHITE +"None",null);
private String name;
private TeamType teamOwned;
private Point(String name,TeamType team)
this.name = name;
teamOwned = team;
public TeamType getTeamOwned()
return teamOwned;
public String getName()
return name;
@Override
public String toString()
return name;
There's obviously something that's happening outside of my knowledge of Java.
Could it possibly be that the Point Enum is not initialized yet when TeamType enum is. This could explain why it's null.
I need some help.
java enums null
Whenever I try to get a field from an enum, it always returns null.
I've set the value of it according to the enum constructor. It still comes out null.
public enum TeamType {
RED("Red",ChatColor.RED,DyeColor.RED,Point.RED),
BLUE("Blue",ChatColor.BLUE,DyeColor.BLUE,Point.BLUE); //<----Set as Point.RED/BLUE
private String name;
private int crystalHealth = 50;
private Point point;
private int teamPoints;
private ChatColor chatColor;
private DyeColor dye;
private HashSet<ArenaPlayer> playerList = new HashSet<>();
private List<ArenaPlayer> queue = new ArrayList<ArenaPlayer>();
private Location spawn;
public Point getPoint()
if(point == null)
System.out.println("WHY? for: " + this.toString()); //<---This always runs
return point;
private TeamType(String name,ChatColor color,DyeColor dye,Point point1)
this.name = name;
this.point = point1; // <--- My assignment
this.dye = dye;
this.chatColor = color;
The Point enum class
public enum Point{
RED(ChatColor.RED + "Red",TeamType.RED),
BLUE(ChatColor.BLUE + "Blue",TeamType.BLUE),
NEUTRAL(ChatColor.WHITE +"None",null);
private String name;
private TeamType teamOwned;
private Point(String name,TeamType team)
this.name = name;
teamOwned = team;
public TeamType getTeamOwned()
return teamOwned;
public String getName()
return name;
@Override
public String toString()
return name;
There's obviously something that's happening outside of my knowledge of Java.
Could it possibly be that the Point Enum is not initialized yet when TeamType enum is. This could explain why it's null.
I need some help.
java enums null
java enums null
edited Mar 28 at 8:11
Artish1
asked Mar 28 at 8:02
Artish1Artish1
188 bronze badges
188 bronze badges
You have not initialised the fieldpoint, so no surprise.
– Jagger
Mar 28 at 8:04
pointis initialized in the constructor? @Jagger
– Artish1
Mar 28 at 8:05
2
Can you show the code ofPointclass/enum? The code here seems fine, hence I suspectPoint.BLUEitself might be pointing tonull
– Pushpesh Kumar Rajwanshi
Mar 28 at 8:09
@PushpeshKumarRajwanshi Sure! I edited to add thePointenum class
– Artish1
Mar 28 at 8:12
2
You seem to have some circular dependency leading tonullYou might want to get rid of that.
– Pushpesh Kumar Rajwanshi
Mar 28 at 8:16
|
show 1 more comment
You have not initialised the fieldpoint, so no surprise.
– Jagger
Mar 28 at 8:04
pointis initialized in the constructor? @Jagger
– Artish1
Mar 28 at 8:05
2
Can you show the code ofPointclass/enum? The code here seems fine, hence I suspectPoint.BLUEitself might be pointing tonull
– Pushpesh Kumar Rajwanshi
Mar 28 at 8:09
@PushpeshKumarRajwanshi Sure! I edited to add thePointenum class
– Artish1
Mar 28 at 8:12
2
You seem to have some circular dependency leading tonullYou might want to get rid of that.
– Pushpesh Kumar Rajwanshi
Mar 28 at 8:16
You have not initialised the field
point, so no surprise.– Jagger
Mar 28 at 8:04
You have not initialised the field
point, so no surprise.– Jagger
Mar 28 at 8:04
point is initialized in the constructor? @Jagger– Artish1
Mar 28 at 8:05
point is initialized in the constructor? @Jagger– Artish1
Mar 28 at 8:05
2
2
Can you show the code of
Point class/enum? The code here seems fine, hence I suspect Point.BLUE itself might be pointing to null– Pushpesh Kumar Rajwanshi
Mar 28 at 8:09
Can you show the code of
Point class/enum? The code here seems fine, hence I suspect Point.BLUE itself might be pointing to null– Pushpesh Kumar Rajwanshi
Mar 28 at 8:09
@PushpeshKumarRajwanshi Sure! I edited to add the
Point enum class– Artish1
Mar 28 at 8:12
@PushpeshKumarRajwanshi Sure! I edited to add the
Point enum class– Artish1
Mar 28 at 8:12
2
2
You seem to have some circular dependency leading to
null You might want to get rid of that.– Pushpesh Kumar Rajwanshi
Mar 28 at 8:16
You seem to have some circular dependency leading to
null You might want to get rid of that.– Pushpesh Kumar Rajwanshi
Mar 28 at 8:16
|
show 1 more comment
2 Answers
2
active
oldest
votes
Well, I think the source of the problem is that you have a circular reference. TeamType has a Point reference and vice versa.
Suppose the TeamType enum class is initialized, then the enum constants are initialized as well. These refer to Point, which is in turn initialized. The classloader loads the Point class, but will not initialize TeamType again. At this point, properties you expect to be non-null are still null.
The JLS § 12.4 defines this process.
add a comment |
Suppose we have a class called A which has class B’s Object. (in UML terms A HAS B). at the same time we class B is also composed of Object of class A (in UML terms B HAS A). obviously this represents circular dependency because while creating the object of A, the compiler must know the size of B... on the other hand while creating object of B, the compiler must know the size of A. this is something like egg vs. chicken problem...
to avoid such type of circular dependency you can use any proxy interface .
https://dzone.com/articles/tackling-circular-dependency
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392680%2fenum-variable-is-found-to-be-null-when-not-set-that-way%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Well, I think the source of the problem is that you have a circular reference. TeamType has a Point reference and vice versa.
Suppose the TeamType enum class is initialized, then the enum constants are initialized as well. These refer to Point, which is in turn initialized. The classloader loads the Point class, but will not initialize TeamType again. At this point, properties you expect to be non-null are still null.
The JLS § 12.4 defines this process.
add a comment |
Well, I think the source of the problem is that you have a circular reference. TeamType has a Point reference and vice versa.
Suppose the TeamType enum class is initialized, then the enum constants are initialized as well. These refer to Point, which is in turn initialized. The classloader loads the Point class, but will not initialize TeamType again. At this point, properties you expect to be non-null are still null.
The JLS § 12.4 defines this process.
add a comment |
Well, I think the source of the problem is that you have a circular reference. TeamType has a Point reference and vice versa.
Suppose the TeamType enum class is initialized, then the enum constants are initialized as well. These refer to Point, which is in turn initialized. The classloader loads the Point class, but will not initialize TeamType again. At this point, properties you expect to be non-null are still null.
The JLS § 12.4 defines this process.
Well, I think the source of the problem is that you have a circular reference. TeamType has a Point reference and vice versa.
Suppose the TeamType enum class is initialized, then the enum constants are initialized as well. These refer to Point, which is in turn initialized. The classloader loads the Point class, but will not initialize TeamType again. At this point, properties you expect to be non-null are still null.
The JLS § 12.4 defines this process.
edited Mar 28 at 8:24
answered Mar 28 at 8:18
MC EmperorMC Emperor
10.2k12 gold badges56 silver badges92 bronze badges
10.2k12 gold badges56 silver badges92 bronze badges
add a comment |
add a comment |
Suppose we have a class called A which has class B’s Object. (in UML terms A HAS B). at the same time we class B is also composed of Object of class A (in UML terms B HAS A). obviously this represents circular dependency because while creating the object of A, the compiler must know the size of B... on the other hand while creating object of B, the compiler must know the size of A. this is something like egg vs. chicken problem...
to avoid such type of circular dependency you can use any proxy interface .
https://dzone.com/articles/tackling-circular-dependency
add a comment |
Suppose we have a class called A which has class B’s Object. (in UML terms A HAS B). at the same time we class B is also composed of Object of class A (in UML terms B HAS A). obviously this represents circular dependency because while creating the object of A, the compiler must know the size of B... on the other hand while creating object of B, the compiler must know the size of A. this is something like egg vs. chicken problem...
to avoid such type of circular dependency you can use any proxy interface .
https://dzone.com/articles/tackling-circular-dependency
add a comment |
Suppose we have a class called A which has class B’s Object. (in UML terms A HAS B). at the same time we class B is also composed of Object of class A (in UML terms B HAS A). obviously this represents circular dependency because while creating the object of A, the compiler must know the size of B... on the other hand while creating object of B, the compiler must know the size of A. this is something like egg vs. chicken problem...
to avoid such type of circular dependency you can use any proxy interface .
https://dzone.com/articles/tackling-circular-dependency
Suppose we have a class called A which has class B’s Object. (in UML terms A HAS B). at the same time we class B is also composed of Object of class A (in UML terms B HAS A). obviously this represents circular dependency because while creating the object of A, the compiler must know the size of B... on the other hand while creating object of B, the compiler must know the size of A. this is something like egg vs. chicken problem...
to avoid such type of circular dependency you can use any proxy interface .
https://dzone.com/articles/tackling-circular-dependency
answered Mar 28 at 8:57
TanvirChowdhuryTanvirChowdhury
8157 silver badges16 bronze badges
8157 silver badges16 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392680%2fenum-variable-is-found-to-be-null-when-not-set-that-way%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You have not initialised the field
point, so no surprise.– Jagger
Mar 28 at 8:04
pointis initialized in the constructor? @Jagger– Artish1
Mar 28 at 8:05
2
Can you show the code of
Pointclass/enum? The code here seems fine, hence I suspectPoint.BLUEitself might be pointing tonull– Pushpesh Kumar Rajwanshi
Mar 28 at 8:09
@PushpeshKumarRajwanshi Sure! I edited to add the
Pointenum class– Artish1
Mar 28 at 8:12
2
You seem to have some circular dependency leading to
nullYou might want to get rid of that.– Pushpesh Kumar Rajwanshi
Mar 28 at 8:16