String NullErrorException

Discussion in 'Spigot Plugin Development' started by XxFroggyKnightxX, May 22, 2016.

  1. Alright so just a straight forward rundown of my problem is that I'm using

    Code (Text):

    String map_name = plugin.getConfig().getString("Maps." + storage.current_map + ".name");
     
    for getting a name of the current map integer with a String. Now, where it confuses me is the fact it gives me a java.lang.NullPointerException if anyone knows why it's causing this, please do let me know. Thanks.
     
    #1 XxFroggyKnightxX, May 22, 2016
    Last edited: May 22, 2016
  2. plugin could be null storage.current_map could be null, the return value from getConfig() could be null. Do null checks
     
    • Agree Agree x 1
  3. alrighty, thanks.
     
  4. I'm gonna assume you're sure that your string isn't empty.

    "plugin" is likely null.

    this. ignore me.
     
  5. Choco

    Moderator

    1. Code brackets are square brackets, and not diamond brackets ;)
    2. Your naming conventions are strange. Use lowerCamelCase
    3. Plugin could potentially be null

    EDIT: Damn I got sniped real hard there
     
  6. Since you guys have been saying "plugin" could be null. I'm using this
    Code (Text):
     
    public static me.xfrogx.Main plugin;

    public StartGame(me.xfrogx.Main m) {
        plugin = m;
    }
     
    for getting the main in plugin for the string.
     
  7. It's okay :3
     
    • Friendly Friendly x 1
  8. Where do you define storage.current_map?
     
    • Agree Agree x 1
  9. Inside of my storage class, where I made the public static ints.
     
  10. Can you show me the code where it's defined?
     
  11. Hold up I think I got it. Testing it quick
     
  12. Code (Text):

    public class storage implements Listener{
        public static me.xfrogx.Main plugin;

        public storage(me.xfrogx.Main m) {
            plugin = m;
        }

        public static HashMap<Player, UUID> Blue = new HashMap<Player, UUID>();
        public static HashMap<Player, UUID> Red = new HashMap<Player, UUID>();
        public static HashMap<Player, UUID> Spec = new HashMap<Player, UUID>();

        public static String yes = "yes";
        public static String no = "no";

        public static int red_wool = 10;
        public static int blue_wool = 10;

        public static int current_map = 1;
        public static int next_map = 2;
        public static int prev_map = 0;

        public static int countdown = 30;

        public static HashMap<String, Boolean> lobby = new HashMap<String, Boolean>();
        public static HashMap<String, Boolean> starting = new HashMap<String, Boolean>();
        public static HashMap<String, Boolean> in_game = new HashMap<String, Boolean>();
        public static HashMap<String, Boolean> end_game = new HashMap<String, Boolean>();

        public static HashMap<String, Boolean> won = new HashMap<String, Boolean>();


    }
     
    that's the whole class storage.
     
  13. Can you give us the full error message?
     
  14. Code (Text):

    at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
    Caused by: java.lang.NullPointerException
            at me.xfrogx.Game.StartGame.startGame(StartGame.java:43) ~[?:?]
            at me.xfrogx.Cmds.StartCMD.onCommand(StartCMD.java:33) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[1.9.2.jar:git-Spigot-e6f93f4-d884ab3]
            ... 15 more

     
     
  15. Show us what's on line 43 of StartGame, and line 33 of StartCMD
     
  16. StartCMD is just the void, StartGame. And line 43 is the Strings that're giving me the error.
     
  17. It says that the error is being caused at StartCMD line 33, as well as the line you already showed us. What is it?
     
  18. Code (Text):

    if (cmd.getName().equalsIgnoreCase("start")) {
        if (p.hasPermission("server.owner")) {

          //  Start.StartGame(p); // called when command is ran \\
            Bukkit.broadcastMessage("TTT");
            StartGame.startGame();

        }
    }
     
    That's line 33 of the StartCMD.
     
  19. I think I might've found the error, not too sure. But could it possibly be the fact that I'm making a string using an integer?
     
  20. Hold on, is the method that string is in static? If it is then the problem is plugin.