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

                      1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      인천여자상업고등학교 목차 학교 연혁 설치 학과 학교 동문 참고 자료 각주 외부 링크 둘러보기 메뉴북위 37° 28′ 05″ 동경 126° 37′ 41″ / 북위 37.4680025° 동경 126.6279602°  / 37.4680025; 126.6279602인천여자상업고등학교“인천광역시립학교 설치조례 별표1”인천여자상업고등학교 홈페이지eheh문서를 완성해