Error with yaml String Lists

Discussion in 'Plugin Development' started by Benni1000, Dec 20, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Benni1000

    Hey :) ,
    I tried using a StringList in my Plugin to let the user define a message that is longer than 1 line.
    This is my Plugin Code:
    PHP:
    package me.Benni1000.noob;

    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.List;
    import java.util.Scanner;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class 
    noob extends JavaPlugin{
        static final 
    Logger log Logger.getLogger("Minecraft");
        protected 
    FileConfiguration config;
        public List<
    Stringmessages;
        public 
    Object[] stringList;
        @
    Override
        
    public void onDisable() {
            
    log.info("Noob disabled!");
        }

        @
    Override
        
    public void onEnable() {
            
    File configdir = new File("plugins/noob");
            if(!
    configdir.exists())  {
                
    configdir.mkdir();
            }
            
    File configFile = new File("plugins/noob/config.yml");
            if(!
    configFile.exists()) {
                
    FileWriter fw null;
                try {
                    
    configFile.createNewFile();
                    
    Scanner sc = new Scanner(this.getResource("config.yml"));
                    
    fw = new FileWriter(configFile);
                    while(
    sc.hasNextLine()) {
                        
    fw.write(sc.nextLine()+"\n");
                    }
                } catch (
    IOException ex) {
                    
    Logger.getLogger(noob.class.getName()).log(Level.SEVEREnullex);
                } finally {
                    try {
                        
    fw.close();
                    } catch (
    IOException ex) {
                        
    Logger.getLogger(noob.class.getName()).log(Level.SEVEREnullex);
                    }
                }
            }
            
    this.messages config.getStringList("message");
            
    this.stringList this.messages.toArray();
            
    log.info("Noob enabled!");
        }
        @
    Override
        
    public boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args)
      {
        if (
    cmd.getName().equalsIgnoreCase("noob"))
        {
          if (!(
    sender instanceof Player)) {
            return 
    true;
          }
          
    sender.getServer().broadcastMessage("Test");
          
    int i stringList.length;
          while(
    i<stringList.length) {
              
    sender.getServer().broadcastMessage(stringList[i].toString());
              
    i--;
          }
          return 
    true;
        }
        return 
    false;
      }
    }
    But when i start my server i get a Null Pointer Exception on this line:
    PHP:
    this.messages config.getStringList("message");
    :( I am working the first time with this Lists.
    Could you please help me?
    Here is my configuration File:
    Code:
    message:
    - §4First Line
    - §5Second Line
    Sorry for my bad english i try to do as best as i can but German is my foreign language.
     
  2. Offline

    Crash

    Where do you ever set config to something?
     
  3. Offline

    Benni1000

    :confused: i totally missed that.
    Thank you ! :D
     
Thread Status:
Not open for further replies.

Share This Page