Solved Error in my code

Discussion in 'Spigot Plugin Development' started by CreepersGamingMc, Jun 9, 2017.

Thread Status:
Not open for further replies.
  1. Hello, so in my code, string builder is underlined in red, this thing: StringBuilder str = new StringBuilder();
    Keep in mind, I accidentally made the wrong name XD
    https://pastebin.com/JZNhgFEH
     
  2. Missing import. Learn Java :)
     
    • Agree Agree x 1
  3. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Can you tell us what the error is?
     
  4. What is the missing import?
     
  5. For the command listeners? There arent supposed to be.
     
  6. You just need to import StringBuilder. I believe it's in java.util.
     
  7. unreachable code
     
  8. Okay
     
  9. It's not needed to be imported, it just says unreachable code.
     
  10. My bad. That was a stupid suggestion on my part.

    It says unreachable code because you didn't wrap the things in your if statement with curly braces. So you are returning true prematurely, so the rest of your code does not get read because you already finished the method.
    Change:
    Code (Java):
    if (cmd.getName().equalsIgnoreCase("plugins"))
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "/plugins"));
        return true;
    to
    Code (Java):
    if (cmd.getName().equalsIgnoreCase("plugins")) {
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "/plugins"));
        return true;
    }
    This is a very beginner mistake, and if you really couldn't figure out, you definitely need to learn more Java.
     
    • Agree Agree x 1
  11. Ok thx
     
Thread Status:
Not open for further replies.