the local variable may not be initialized

Discussion in 'Plugin Development' started by TheGamesHawk2001, Nov 13, 2014.

Thread Status:
Not open for further replies.
  1. hey, does anyone know how to fix this??

    Code:java
    1. if (sender.hasPermission("hi.use"));
    2. sender.sendMessage(ChatColor.RED + "You do not have enough permissions to use this command.");
    3. if (cmd.getName().equalsIgnoreCase("hi")) {
    4. Player p = p.getPlayer();
    5. if (args.length == 0) {
    6. p.sendMessage(ChatColor.GRAY + "Hi);
    7. return true;
     
  2. Offline

    Rocoty

    You are not explaining your problem, nor are you posting sufficient code for us to help you. Not much we can do, sorry. I would point out that you are not closing the last String literal in that code snippet, but that might just be a copy-paste error.

    EDIT: Another potential problem I just spotted: After the first if-statement you have an empty statement. So the statement underneath will be executed regardless. As a rule of thumb I like to always use brackets to prevent such errors.
     
  3. Rocoty I snipped a bit out of my whole code. I do have {} etc
     
  4. Offline

    jensdeboom

    TheGamesHawk2001 Should post your whole code + tell us wich line/variable gives you the error...
     
  5. Offline

    mrkirby153

    TheGamesHawk2001

    I'm assuming if you're getting a "Local variable not initialized" error, then on that line of the error, change it to
    Code:java
    1. <YOUR VARIABLE DEFINITION HERE> = null;
    Just be sure to check if the variable you are trying to use is not null, otherwise, you'll end up with a NullPointerException
     
Thread Status:
Not open for further replies.

Share This Page