Stack Overflow Error

Discussion in 'Plugin Development' started by Ice_Sword, Feb 6, 2012.

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

    Ice_Sword

    Suggestions?

    Code:
    Could not load 'plugins\ArrowPickUp.jar' in folder 'plugins':
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:136)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:285)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:200)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:156)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:132)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:148)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.StackOverflowError
        at arrowpickup.PL.<init>(PL.java:34)
        at arrowpickup.Arrowclass.<init>(Arrowclass.java:23)

    Here's my syntax:
    Code:java
    1. /*
    2. * To change this template, choose Tools | Templates
    3. * and open the template in the editor.
    4. */
    5. package arrowpickup;
    6.  
    7. import java.util.List;
    8. import java.util.logging.Logger;
    9. import org.bukkit.Material;
    10. import org.bukkit.entity.Arrow;
    11. import org.bukkit.entity.Entity;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.player.PlayerMoveEvent;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.inventory.PlayerInventory;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19.  
    20. /**
    21. *
    22. * @author Ice_Sword
    23. */
    24. public class PL extends Arrowclass implements Listener
    25. {
    26.  
    27. private final JavaPlugin plugin;
    28. static final Logger log = Logger.getLogger("Minecraft");
    29. private Arrowclass listener;
    30.  
    31.  
    32. //Constructor
    33. public PL(JavaPlugin plugin)
    34. {
    35. this.plugin = (PL)plugin;
    36. this.getServer().getPluginManager().registerEvents(this, this.plugin);
    37. }
    38.  
    39.  
    40.  
    41.  
    42. //Checks for nearby arrows
    43. public boolean hasArrows(List<Entity> list){
    44. for(Entity entity: list){
    45. if(entity instanceof Arrow) return true;
    46. }
    47. return false;
    48. }
    49.  
    50. @EventHandler
    51. public void onPlayerMove(PlayerMoveEvent event){
    52. List<Entity> nears = event.getPlayer().getNearbyEntities(3,4,3);
    53. //the (3,4,3) is the box to check for entities
    54. if(hasArrows(nears))
    55. {
    56. Player player = event.getPlayer();
    57. player.getName();
    58. PlayerInventory inventory = player.getInventory();
    59. ItemStack ar = new ItemStack(Material.ARROW, 1);
    60. inventory.addItem(ar);
    61. }
    62. }
    63.  
    64.  
    65. }
    66.  


    I've got another class, my main class. I can post that if need be.
     
  2. Offline

    nisovin

    What is Arrowclass, and why does your listener extend it?
     
  3. Offline

    Ice_Sword

    Arrowclass is my main class. And line 35 and 36 give me an error if I don't extend Arrowclass. This got so convoluted while I was trying to program it, I started changing variables and added and removed things just hoping I could get it to compile. Which was a bad choice in hindsight. So, any suggestions would be helpful. And, if "start over" is your suggestions, please, by all means, tell me so. Just point me in the right direction. I've gotten lost in a lot of this. :/ I need to study Java more.

    This is "Arrowclass":

    Code:java
    1.  
    2. /*
    3. * To change this template, choose Tools | Templates
    4. * and open the template in the editor.
    5. */
    6. package arrowpickup;
    7.  
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12.  
    13. /**
    14. *
    15. * @author Ice_sword
    16. */
    17. public class Arrowclass extends JavaPlugin
    18. {
    19. public static void main(String[] args)
    20. {
    21. }
    22.  
    23.  
    24. private PL playerListener = new PL(this);
    25.  
    26.  
    27. @Override
    28. public void onEnable()
    29. {
    30. }
    31.  
    32. @Override
    33. public void onDisable()
    34. {
    35. }
    36. PluginManager pm = this.getServer().getPluginManager();
    37.  
    38.  
    39.  
    40.  
    41.  
    42. }
    43.  



    By the way, I love BookWorm!
     
  4. Offline

    nisovin

    The problem with extending your main class is it creates a PL in its constructor. So every time to create a new PL, you also create a new Arrowclass, which creates a new PL, which is also an Arrowclass, which creates a new PL.... You get the idea. You can't extend Arrowclass here, it's not needed. You also shouldn't be casting your plugin to a PL, since it's not a PL, it's an Arrowclass.

    I think you might want to find a good Java tutorial, especially one that focuses on OOP, since that's what you're failing to understand here.
     
    Ice_Sword likes this.
  5. Offline

    Ice_Sword

    Perhaps. That's a bit of a blow to my ego, but, you're probably right. I'll see about a tutorial. Thank you, sir.
     
Thread Status:
Not open for further replies.

Share This Page