Solved Very strange problem with visibility of a static variable

Discussion in 'Spigot Plugin Development' started by Xearox, May 28, 2016.

  1. Hey there,

    I've got a very very strange problem with the visibility of a static variable.

    I got this error in eclipse
    Code (Text):
    The field SetLanguageClass.ErrMojangAPINotAvailable is not visible
    In other classes is the static variable visible and in an other plugin I use this too but there it works.

    I dont really know what the different is of this here(which dont work):
    https://github.com/Xearoxde/Maven/blob/master/xDaily/src/main/java/de/xearox/xdaily/XDaily.java#L158
    and the languageClass it selt:
    https://github.com/Xearoxde/Maven/b.../de/xearox/xdaily/utilz/SetLanguageClass.java

    and(what work):
    https://github.com/Xearoxde/Maven/b...main/java/de/xearox/xhome/MainClass.java#L176
    and the languageClass it self:
    https://github.com/Xearoxde/Maven/b...in/java/de/xearox/xhome/SetLanguageClass.java


    The problem is that the SetLanguageClass is the same except the last lines from xDaily(generated from eclipse) and in the other classes I can use SetLanguageClass.ErrMojangAPINotAvailable without any getter/setter.

    Maybe you can help me out here. Maybe I have tomatoes on my eyes :D

    Thank You very much =)
     
  2. The visibility of it is package local. You need to set it to public.
     
    • Agree Agree x 1
    • Agree Agree x 1
  3. Yes I know that this solve the problem but that is not what I want to know. The SetLanguageClass from xHome works without public static! And in the other classes from the xDaily plugin I can use SetLanguageClass.ErrMojangAPINotAvailable.

    You know what the problem is which I have? Both classes are the same(Just copy/paste them and adjust it for the new plugin).
     
  4. I told you.. When you don't specify an access modifier, the default (Package local) modifier is used. https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
     
  5. Okay, I understand now the problem. In my xHome plugin I dont use sub-packages but in the xDaily plugin that is the reason why I can use SetLanguageClass.xxx in the CreateFiles class without problems and in the main package not.

    The only way to access them is to use the public modifier in front of the static, right? or do I have an other way to set the package to public?