Development Assistance Null Pointer Exception

Discussion in 'Plugin Help/Development/Requests' started by TheCwispyOne, Oct 11, 2014.

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

    TheCwispyOne

    Ok so I made another thread about getting methods from different classes and I kinda fixed my problem but I also kinda didn't.
    GalaxiesFile.java:
    Code:java
    1. public class GalaxiesFile {
    2.  
    3. public Cmds plugin;
    4. public GalaxiesFile(Cmds plugin) {
    5. this.plugin = plugin;
    6. }
    7.  
    8. public File GalaxiesFile = null;
    9. public FileConfiguration Galaxies = null;
    10.  
    11. public void reloadGalaxies() {
    12. if (GalaxiesFile == null) {
    13. GalaxiesFile = new File(plugin.getDataFolder(), "Galaxies.yml");
    14. }
    15. Galaxies = YamlConfiguration.loadConfiguration(GalaxiesFile);
    16. }
    17.  
    18. public FileConfiguration getGalaxies() {
    19. if (Galaxies == null) {
    20. reloadGalaxies();
    21. }
    22. return Galaxies;
    23. }
    24.  
    25. public void saveGalaxies() {
    26. try {
    27. Galaxies.save(GalaxiesFile);
    28. } catch (IOException e) {
    29. plugin.getLogger().info(ChatColor.RED + "Could not save Galaxies.yml.");
    30. }
    31. }
    32. }
    33.  

    part of Cmds.java:
    Code:java
    1. private GalaxiesFile gfile;
    2.  
    3. public void onEnable() {
    4. makeDataFolder();
    5. saveDefaultConfig();
    6. gfile.reloadGalaxies();//this is line 32
    7. gfile.saveGalaxies();
    8. new BlockPhysics(this);
    9. PluginManager pm = getServer().getPluginManager();
    10. pm.addPermission(planetwars);
    11. }

    Stack trace:
    Code:
    [20:56:07 INFO]: [Planet_Wars] Enabling Planet_Wars v1.0
    [20:56:07 ERROR]: Error occurred while enabling Planet_Wars v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at thecwispyone.main.Cmds.onEnable(Cmds.java:32) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[spigot.jar:git-Spigot-1443]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [spigot.jar:git-Spigot-1443]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-1443]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugin(CraftServer.java:467) [spigot.jar:git-Spigot-1443]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.enablePlugins(CraftServer.java:385) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.MinecraftServer.n(MinecraftServer.java:359) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.MinecraftServer.g(MinecraftServer.java:333) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.MinecraftServer.a(MinecraftServer.java:289) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.DedicatedServer.init(DedicatedServer.java:193) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:450) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1443]
    
    Ok so I'm not sure why it's a null pointer exception. Help?
     
  2. Offline

    Mmarz11

    TheCwispyOne You never initialized gfile in Cmds.java which results in it being null by default. You then call a method on the gfile variable resulting in the NullPointerException.
     
  3. Offline

    TheCwispyOne

    Mmarz11 You have a good point there sir :) Maybe I should sleep a bit earlier...

    Mmarz11 Ok so i just tested it out. I did:
    Code:java
    1. private GalaxiesFile gfile;
    2. private Cmds(GalaxiesFile gfile) {
    3. this.gfile = gfile;
    4. }

    I still got no errors in eclipse but now the error in the console is Abnormal Plugin type. Could you show me how I'm supposed to do this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
    mine-care likes this.
  4. Offline

    Gamecube762

  5. Offline

    TheCwispyOne

    I guess...it doesn't give the line of the error. It just says abnormal plugin type.
    Here's the error:
    Code:
    [10:32:10 ERROR]: Could not load 'plugins/PlanetWars.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: Abnormal plugin type
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:56) ~[spigot.jar:git-Spigot-1443]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[spigot.jar:git-Spigot-1443]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-1443]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-1443]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugins(CraftServer.java:360) [spigot.jar:git-Spigot-1443]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.reload(CraftServer.java:818) [spigot.jar:git-Spigot-1443]
        at org.bukkit.Bukkit.reload(Bukkit.java:286) [spigot.jar:git-Spigot-1443]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:24) [spigot.jar:git-Spigot-1443]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) [spigot.jar:git-Spigot-1443]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:722) [spigot.jar:git-Spigot-1443]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchServerCommand(CraftServer.java:709) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.DedicatedServer.aB(DedicatedServer.java:319) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:284) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:576) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:482) [spigot.jar:git-Spigot-1443]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1443]
    Caused by: java.lang.InstantiationException: thecwispyone.main.Cmds
        at java.lang.Class.newInstance(Class.java:418) ~[?:1.8.0]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[spigot.jar:git-Spigot-1443]
        ... 15 more
    Caused by: java.lang.NoSuchMethodException: thecwispyone.main.Cmds.<init>()
        at java.lang.Class.getConstructor0(Class.java:2971) ~[?:1.8.0]
        at java.lang.Class.newInstance(Class.java:403) ~[?:1.8.0]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[spigot.jar:git-Spigot-1443]
        ... 15 more
    
     
  6. Offline

    ZeldoKavira

    This is spigot, moved the appropriate forums. Please make sure you are posting in the right sections.
     
Thread Status:
Not open for further replies.

Share This Page