Solved NullPointerException on getData();

Discussion in 'Spigot Plugin Development' started by darkshadow22mc, Jun 1, 2016.

Thread Status:
Not open for further replies.
  1. Basically everything: your code is a disorganized mess. you need to just start over and learn more - mistakes happen, you should have seen the disaster that was my first C++ project. Very often if you just start over, re-using some of the working code, a project goes much faster the second time, and ends up smaller and cleaner.

    Three days is very little time to spend on a programming project, especially when you are learning.

    Java is not very user-friendly, in that is thrusts you straight into OOP and forces you to learn about classes, inheritance and polymorphism while also trying to learn basics. It can sound like a lot of nonsense if you are not already familiar with the terms.


    About anonymous classes: it acts like a new unnamed class that extends whatever the base class is (ActionListener), and it is its own object.

    There is a difference between a class and an object. a class is the code used by all objects of the class, an object is a completely individual instance of that class, with its own variables, location in memory, ect.

    So, you cannot register a class as listener, you have to register a specific object of that class, and only that object will receive events. You can then make a few other classes if you want to split up the events by type, and make the listener class call methods in those classes - this is purely to organize code.

    If you want to have different anonymous classes that run event code, give the base class a method that the anonymous class can override with the desired event code, add them to a list when you create them, and have the actual event in the listener loop over that list and trigger the overriden method for each one.

    It sounds complex, but the alternative is heretical pasta programming.
     
  2. Ok, so as this thread is going nowhere and I've decided to follow the steps of FlyingLlama I lock and set to Solved this thread,
     
Thread Status:
Not open for further replies.