Integer++ problem

Discussion in 'Plugin Development' started by javoris767, May 4, 2013.

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

    javoris767

    I had this same method in other version, but now its getting errors in the console.
    Code:
    Code:
                // Add to FlatFile
                if (_plugin.getConfig().getBoolean("VoteSQL.FlatFile.Enabled") == true)
                {   
                    if(username != "" || username != null) {
                        Integer numberOfVotes = VoteSQLAPI.voteMap.get(username.toLowerCase());
                       
                        numberOfVotes++;
                       
                        VoteSQLAPI.voteMap.put(username.toLowerCase(), numberOfVotes));
                        VoteSQLAPI.saveDataFile();
                        VoteSQLChat.logInfo("Calling Flatfile");
                    }
                }

    Error:
    Code:
    04.05 19:51:30 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    04.05 19:51:30 [Server] INFO at java.lang.reflect.Method.invoke(Unknown Source)
    04.05 19:51:30 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    04.05 19:51:30 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    04.05 19:51:30 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    04.05 19:51:30 [Server] INFO at me.javoris767.votesql.listeners.VotingListener.onVote(VotingListener.java:91)
    04.05 19:51:30 [Server] INFO Caused by: java.lang.NullPointerException
    04.05 19:51:30 [Server] INFO at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    04.05 19:51:30 [Server] INFO at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
    04.05 19:51:30 [Server] INFO at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
    04.05 19:51:30 [Server] INFO at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
    04.05 19:51:30 [Server] INFO at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:513)
    04.05 19:51:30 [Server] INFO at org.bukkit.craftbukkit.v1_5_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    04.05 19:51:30 [Server] INFO at org.bukkit.craftbukkit.v1_5_R3.scheduler.CraftTask.run(CraftTask.java:53)
    04.05 19:51:30 [Server] INFO at com.vexsoftware.votifier.net.VoteReceiver$1.run(VoteReceiver.java:181)
    04.05 19:51:30 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    04.05 19:51:30 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    04.05 19:51:30 [Server] INFO at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:35)
    04.05 19:51:30 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    04.05 19:51:30 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    04.05 19:51:30 [Server] INFO org.bukkit.event.EventException
    04.05 19:51:30 [Server] SEVERE Could not pass event VotifierEvent to VoteSQL v1.3
    I've tried many different solutions, but none worked :/

    Line 91:
    Code:
    numberOfVotes++;
    
     
  2. Offline

    Tirelessly

    numberOfVotes is null..
     
  3. Offline

    Digi

    javoris767
    Integer is an object and can be asigned to null.

    I guess that voteMap is a Map object, then it's most likely that the key you supplied isn't set there... therefore it returns null and asigns 'numberOfVotes' to null.

    You can either check against null if you want to detect when the key doesn't exist or just use the primitive 'int' type instead of 'Integer' and it will be automatically set to 0 if null.
     
Thread Status:
Not open for further replies.

Share This Page