itemmeta.setDisplayName() Throws A Very Weird Error

Discussion in 'Spigot Plugin Development' started by TheShermanTanker, May 28, 2017.

  1. I was setting the name of Green Wool so I did this:

    Code (Java):
    ItemStack greenwool = new ItemStack(Material.WOOL, 1, (byte)13);
    ItemMeta greenmeta = greenwool.getItemMeta();
    greenmeta.setDisplayName(ChatColor.GREEN + "Green Team - " + ChatColor.BOLD + "CLICK TO JOIN!");
    what happened was that at .setDisplayName() the . and the ; got underlined in red indicating that an error had occured. When I checked it showed a few errors which were something like: Unexpected token "." @ expected Put ( to start method declaration Put ) to end method declaration Place SimpleName to begin QualifiedName (I'm on a phone now the errors are all from my memory so I might not be 100 percent correct)

    I'm confused as I did everything right, the dot should be there, the method declaration brackets are there, etc. Now because of these errors my entire Plugin won't compile and work. Can someone help?
  2. do you use eclipse or intellij?
    Have you tried restarting it?
    Have you set java as jdk?
    Could you provide an image that shows it red?

    Is there maybe something around your code that is incorrect and produces the issue?
  3. 1. Eclipse Neon
    2. Yes, many many times, both IDE and Server
    3. Yes I did that when I first downloaded Eclipse
    4. Later when i have access to my PC

    I don't think there's an error because nothing above has been reported by Eclipse to be incorrect...
  4. make sure you're declaring and using the setters within a method, not bluntly within the class. show your entire class.
  5. Hey buddy , change

    Code (Text):
    Code (Text):
    I've check it , mine is Eclipse Neon too
  6. Try cleaning the project, Project -> Clean
  7. Hmm wait a sec while Eclipse boots up, ill be right back with the class
  8. fixed it but the problem is still there. It started before I set the item meta
  9. If you want , I could teamviewer and check your problem . Msg me
  10. Ok guys back with the class pics


    upload_2017-5-28_12-59-3.png upload_2017-5-28_12-58-32.png upload_2017-5-28_12-59-3.png
  11. Oh hell no.
  12. Oh!
    I know what the problem is:
    You are writing that code outside of a
    method or constructor.

    You can declare variables outside of
    method and constructors, but you cannot perform
    translations to such objects.
  13. Indeed, too lazy to read that far up :p
  14. Oh dang I thought I was being smart and not cluttering up the method body :/ well when I get home ill fix it