Help needed figuring out <init> error

Discussion in 'Plugin Development' started by TwoPointDuck, Jan 16, 2014.

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

    TwoPointDuck

    I did not study java, and basically just learned it through Bukkit coding.
    So, it'd be nice if someone took a look at this and told me why it doesnt work and how to fix it :p

    Error Log just repeats this (ends in NullPointer, but not sure if it does):
    Code:
    com.twopointduck.variables.MainMaps.getInstance(MainMaps.java:12) ~[?:?]
    16.01 18:09:16 [Server] INFO at com.twopointduck.variables.MainMaps.<init>(MainMaps.java:15) ~[?:?]
    16.01 18:09:16 [Server] INFO at com.twopointduck.variables.TeleportType.getInstance(TeleportType.java:28) ~[?:?]
    16.01 18:09:16 [Server] INFO at com.twopointduck.variables.TeleportType.<init>(TeleportType.java:24) ~[?:?]
    This is how I try to initiate the two classes:

    Code:
        private static MainMaps instance;
        private MainMaps(){}
        public static MainMaps getInstance(){
            if(instance == null)instance = new MainMaps();
            return instance;
        }
        private TeleportType teleporttype = TeleportType.getInstance();
    Code:
        private MainMaps mainmaps = MainMaps.getInstance();
        private static TeleportType instance;
        private TeleportType(){
            loadDefaultLocations();
        }
        public static TeleportType getInstance(){
            if(instance == null)instance = new TeleportType();
            return instance;
        }
    I cut out anything in loadDefaultLocations(); that has nothing to do with MainMaps class;

    Code:
            if(fileloading.locations.getInt("Locations.arenas.arena_amount") == 0){
                mainmaps.setHasNoMaps();
                return;
            }


    Thank you for any responses/help I get.
     
  2. Offline

    coldandtired

    Your two objects are creating instances of each other at the same time.

    If you're using singletons you don't need to store any instances, just use the static method when you need it.
     
  3. Offline

    Necrodoom

    Moved to correct section.
     
  4. Offline

    RawCode

    never perform any actions inside cinit and init as long as you dont understant how JVM works and when this methods will invoke.
     
Thread Status:
Not open for further replies.

Share This Page