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;








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.










share|improve this question


























  • 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






  • 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












  • @PushpeshKumarRajwanshi Sure! I edited to add the Point enum class

    – Artish1
    Mar 28 at 8:12







  • 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


















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.










share|improve this question


























  • 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






  • 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












  • @PushpeshKumarRajwanshi Sure! I edited to add the Point enum class

    – Artish1
    Mar 28 at 8:12







  • 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














0












0








0


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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 field point, so no surprise.

    – Jagger
    Mar 28 at 8:04











  • point is initialized in the constructor? @Jagger

    – Artish1
    Mar 28 at 8:05






  • 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












  • @PushpeshKumarRajwanshi Sure! I edited to add the Point enum class

    – Artish1
    Mar 28 at 8:12







  • 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 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






  • 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












  • @PushpeshKumarRajwanshi Sure! I edited to add the Point enum class

    – Artish1
    Mar 28 at 8:12







  • 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 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













2 Answers
2






active

oldest

votes


















3
















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.






share|improve this answer


































    0
















    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






    share|improve this answer



























      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
      );



      );














      draft saved

      draft discarded
















      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









      3
















      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.






      share|improve this answer































        3
















        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.






        share|improve this answer





























          3














          3










          3









          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


























              0
















              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






              share|improve this answer





























                0
















                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






                share|improve this answer



























                  0














                  0










                  0









                  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






                  share|improve this answer













                  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







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 28 at 8:57









                  TanvirChowdhuryTanvirChowdhury

                  8157 silver badges16 bronze badges




                  8157 silver badges16 bronze badges































                      draft saved

                      draft discarded















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                      Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?