Error... Someone help please?

Discussion in 'Plugin Development' started by edragy, Aug 2, 2012.

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

    edragy

    OK this is probably a very basic error, but I just can't seem to get my head around it.
    Here is the stacktrace that happens while the plugin is being enabled:

    Code:
    2012-08-03 16:32:03 [SEVERE] Error occurred while enabling PetSecure v2.0 (Is it up to date?)
    java.lang.NullPointerException
        at co.nz.creepercraft.updateChecker.versionCheck(updateChecker.java:20)
        at co.nz.creepercraft.PetSecureMain.onEnable(PetSecureMain.java:80)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:257)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:239)
        at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:373)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:360)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:189)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:424)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    And here is updateChecker class

    Code:
    package co.nz.creepercraft;
    
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.logging.Logger;
    
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class updateChecker extends JavaPlugin{
    
    Logger log;
      //Update checker!
      public void versionCheck() {
    
    
            //Perform version check
            log.info("Checking for updates. Please wait.");
            try {
    
              //Values
              int updateVer = 0;
              int curVer = 0;
              //Get version file
              URLConnection yc = new URL("http://creeperminecraft.tk/test.txt").openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
    
            //Get version number
            PluginDescriptionFile pdf = this.getDescription(); //Gets plugin.yml
            String version = pdf.getVersion(); //Gets the version
            String updateVersion = in.readLine().replace(".", "");
            updateVer = Integer.parseInt(updateVersion);
          curVer = Integer.parseInt(version.replace(".", ""));
            
    
            //Check versions
            if (updateVer> curVer) {
            log.warning("A new version of PetSecure is available: " + updateVersion);
            log.warning("Your current version is: " + version);
            }
            else log.info("No updates were found.");
            in.close();
    
        } catch (Exception e) {
          log.severe("Error occoured while checking for updates.");
          e.printStackTrace();
        }
      }
      
      
    }
     
  2. Offline

    michaelb10297

    there's a problem with "log.info("Checking for updates. Please wait.");" If your trying to print it out to the console try "System.out.println("Checking for updates. Please wait.");"
     
  3. Offline

    edragy

    System.out.println only prints out info messages, how do I do warnings and such?
     
  4. Offline

    Darq

    michaelb10297 Wut. Using a Logger is fine.
    edragy You see how you've done Logger log;, well in the onEnable() method, you using log.info before ever initializing log, this is throwing the NPE. So, you can replace your "Logger log;" line with
    Code:
    Logger log = Logger.getLogger("Minecraft");
    
    to fix it.
     
  5. Offline

    michaelb10297

    like errors in game?
     
  6. Offline

    edragy

    ok now I have a error on line 32 of updateChecker. stack trace:

    Code:
    2012-08-03 17:04:57 [SEVERE] java.lang.NullPointerException
    2012-08-03 17:04:57 [SEVERE]     at co.nz.creepercraft.updateChecker.versionCheck(updateChecker.java:32)
    2012-08-03 17:04:57 [SEVERE]     at co.nz.creepercraft.PetSecureMain.onEnable(PetSecureMain.java:80)
    2012-08-03 17:04:57 [SEVERE]     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    2012-08-03 17:04:57 [SEVERE]     at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
    2012-08-03 17:04:57 [SEVERE]     at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
    2012-08-03 17:04:57 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:257)
    2012-08-03 17:04:57 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:239)
    2012-08-03 17:04:57 [SEVERE]     at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:373)
    2012-08-03 17:04:57 [SEVERE]     at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:360)
    2012-08-03 17:04:57 [SEVERE]     at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:189)
    2012-08-03 17:04:57 [SEVERE]     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:424)
    2012-08-03 17:04:57 [SEVERE]     at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    btw, that's my plugin catching the exception then printing stack trace

    Darq can you help?

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

    michaelb10297

    change it back to log

    i tryed it and it said that log wasn't initialized

    try doing
    Code:
    Logger log = Logger.getLogger("Minecraft");
    like darq said

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

    edragy

    No, it's having trouble with this line: String version = pdf.getVersion(); //Gets the version
     
  9. Offline

    michaelb10297

    you have a plugin.yml with a name right?
     
  10. Offline

    Darq

    One question: Why does your updateChecker class extend JavaPlugin when it's not your plugin's main class? You're calling getDescription() off JavaPlugin, but getDescipriton() will simply return null, as this isn't your actual plugin's main class, Bukkit has "ignored it" as a plugin.

    You'll have to pass an instance of your Main class to your updateChecker class (easiest way to do that is in your constructor), and then use that instance of it to call getDescription().
     
  11. Offline

    edragy

    ok so how do I do that?

    OK I've fixed it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page