Solved StackOverflowError?

Discussion in 'Spigot Plugin Development' started by Wilsoon, Jan 24, 2020.

Thread Status:
Not open for further replies.
  1. I may not let you view the code behind this plugin because I chose to not put this command in after facing this error.
    But what exactly does this mean?

    Code (Text):
    null
    org.bukkit.command.CommandException: Unhandled exception executing command 'bal' in plugin MinEco v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_241]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_241]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]
    Caused by: java.lang.StackOverflowError
            at com.gmail.calorious.eco.Main.getMoney(Main.java:154) ~[?:?]
            at com.gmail.calorious.eco.Main.getMoney(Main.java:154) ~[?:?]
            at com.gmail.calorious.eco.Main.getMoney(Main.java:154) ~[?:?]
            at com.gmail.calorious.eco.Main.getMoney(Main.java:154) ~[?:?]
            at com.gmail.calorious.eco.Main.getMoney(Main.java:154) ~[?:?]
            at com.gmail.calorious.eco.Main.getMoney(Main.java:154) ~[?:?]
            at com.gmail.calorious.eco.Main.getMoney(Main.java:154) ~[?:?]
            at com.gmail.calorious.eco.Main.getMoney(Main.java:154) ~[?:?]
            (You get the idea, this "at com.gmail.calorious...." continued for another 1000 times)
     
     
  2. the getMoney method is recursively calling itself infinitely
     
  3. SteelPhoenix

    Moderator

    Your method calls itself infinitely essentially filling up the stack, ergo a stackoverflow error
     
  4. Why even is getMoney recursive?
     
  5. Yup, I just saw that problem.

    Cuz I'm blind (I was messing with Essentials API)

    Side question: (As always I don't want to make 100 threads about my stupid questions so I'll put it here)
    This involves Java Math. How do I check whether a value has increased, then do something, and do something else when the value decreases because of a Minecraft command or something.
     
  6. "Maths" :p
    Code (Java):
    int previousValue = YourPreviousValueHere;

    if (newValue > previousValue) {
        // whatever you want to do here...
    } else if (newValue < previousValue) {
        // or here
    }
     
  7. I'm talking like I have this one value which I want it to when a task is done to increase the value, the code that is meant for decrease wont trigger.
    And vice versa - when a task is done to decrease the value, the code for decrease triggers.



    MATH :)
     
  8. @Schottky is there a way?
     
  9. I am not really sure I understand what you mean... Something like this?

    Code (Java):
    AtomicInteger atomicInt = new AtomicInteger(0);

    // task 1
    new BukkitRunnable() {
        @Override
        public void run() {
            if (atomicInteger.get() == 1) {
                // run your 1st task
                atomicInt.getAndSet(0);
            }
        }
    }.runTaskLater(this, 10L);

    // task 2
    new BukkitRunnable() {
        @Override
        public void run() {
            if (atomicInteger.get() == 0) {
                // run your 2nd task
                atomicInt.getAndSet(0);
            }
        }
    }.runTaskLater(this, 10L);
     
  10. Nah it's fine, thanks.
     
Thread Status:
Not open for further replies.