Solved Whats this error mean (i'm being nooby?)

Discussion in 'Plugin Development' started by xXShadowGuy3Xx, Mar 27, 2013.

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

    xXShadowGuy3Xx

  2. Offline

    TomTheDeveloper

    HelloThereMain.java:66 This means that there is something wrong on line 66 in the HelloThereMain class
    It is a NullPointerException, that means, that you didn't defined something correctly, the server sees it as null, nothing
     
  3. Offline

    Nitnelave

    If you need more help, you'll need to show us some code. Please include the line numbers, so we can see where the error is.
     
  4. Offline

    xXShadowGuy3Xx

    The error was moved to line 71 due to puting line numbers

    Code:
    // Line1
    package com.gmail.kevinscottleflerjr;
     
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Iterator;
    //Line10
    import java.util.List;
    import java.util.logging.Logger;
     
     
     
    import org.bukkit.configuration.InvalidConfigurationException;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    //Line20
    public class HelloThereMain extends JavaPlugin{
    public final Logger logger = Logger.getLogger("Minecraft");
    public final HTPlayerListener pl = new HTPlayerListener(this);
    private List<String> oldPlayers;
    public List<String> messages;
    private String[] defaultArray = { "Hello There dude!", "Welcome!", "Hello, Welcome to the server!", "Howdy Partner!", "Sup?"};
    private List<String> deafaults = Arrays.asList(this.defaultArray);
    public static final int MIN = 5;
    public int range;
    //Line30
     
     
     
    @Override
    public void onDisable(){
        PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName()+" v"+ pdfFile.getVersion() + " has been disabled");
    }
     
    //Line40
     
    @Override
    public void onEnable(){
        PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName()+" v"+ pdfFile.getVersion() + " has been enabled");
        getServer().getPluginManager().registerEvents(new HTPlayerListener(this), this);
        try {
          YamlConfiguration config = new YamlConfiguration();
          File file = new File("plugins/Welcome/" + File.separator + "This_Plugin_Will_Not_Welcome_The_Players_In_This_File_Okay.yml");
          //Line50
          if (!file.exists()) {
            new File("plugins/Welcome/").mkdir();
            file.createNewFile();
          }
          config.load(file);
     
          List<?> list = config.getList("players", new ArrayList<Object>());
          ArrayList<String> strings = new ArrayList<String>();
          for (Iterator<?> localIterator1 = list.iterator(); localIterator1.hasNext(); ) { Object o = localIterator1.next();
          //line60
          strings.add(o.toString());
          }
          this.oldPlayers = strings;
          config.set("players", this.oldPlayers);
          config.save(new File("plugins/HelloThere/" + File.separator + "This_Plugin_Will_Not_Welcome_The_Players_In_This_File_Okay.yml"));
     
          reloadConfig();
          List<?> lisst = getConfig().getList("messages");
          ArrayList<String> stringss = new ArrayList<String>();
          //line70
          for (Iterator<?> localIterator2 = lisst.iterator(); localIterator2.hasNext(); ) { Object o = localIterator2.next();
            stringss.add(o.toString());
          }
          this.messages = stringss;
          getConfig().set("messages", this.messages);
          this.range = getConfig().getInt("timeInTicks", 160);
          getConfig().set("timeInTicks", Integer.valueOf(this.range));
          saveConfig();
        } catch (IOException e) {
        //Line80
            e.printStackTrace();
        } catch (InvalidConfigurationException e) {
          e.printStackTrace();
        }
      }
     
      public boolean isToBeWelcomed(String name) {
        if (this.oldPlayers.contains(name)) return false;
        return true;
        //line90
      }
     
      public void makeOld(String name) {
        YamlConfiguration config = new YamlConfiguration();
        try {
          config.load(new File("plugins/HelloThere/" + File.separator + "This_Plugin_Will_Not_Welcome_The_Players_In_This_File_Okay.yml"));
          this.oldPlayers.add(name);
          config.set("players", this.oldPlayers);
          config.save(new File("plugins/HelloThere/" + File.separator + "This_Plugin_Will_Not_Welcome_The_Players_In_This_File_Okay.yml"));
        //Line100
        } catch (FileNotFoundException e) {
          e.printStackTrace();    } catch (IOException e) {
        e.printStackTrace();
      } catch (InvalidConfigurationException e) {
        e.printStackTrace();
      }
    }
     
     
      //110
    }
    
     
  5. Offline

    Nitnelave

    You should split your code into several methods, each of them doing a specific thing, with a relevant name. That will clarify it a lot. I think your problem here, if the error is on the line I think, is that you don't have a list under the key "messages" in your config.
     
  6. Offline

    xXShadowGuy3Xx

    Like I said I was just trying to update it, meaning I didn't write most of it, I will try your suggestion
     
  7. Offline

    Nitnelave

    If you update someone's code, first understand it (all of it), then re-write it to make it your own (and maybe improve it in the process).
     
  8. Offline

    xXShadowGuy3Xx

    Will do Nitnelave, I just recently started working on java in general, guess it's time to learn hashmaps.
    Good thing it's spring break next week XD

    Ok, so I decided to re-write it, I just need to know, how do I put text into a text file, could I use somthing like this http://www.javapractices.com/topic/TopicAction.do?Id=42 or do I need to do somthing entirely diffrent?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  9. Offline

    Nitnelave

    Yes, it seems good, but don't use the java 7 version, it is recommended to be able to compile on java 6, or even 5.
     
Thread Status:
Not open for further replies.

Share This Page