NullPointerException

Discussion in 'Plugin Development' started by user_90934786, Sep 19, 2014.

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

    user_90934786

    The stack trace:
    The code:
    Code:java
    1. int DPSelect = DPRand();
    2.  
    3. public int DPRand() {
    4. Random rint1 = new Random();
    5. int Low = 0;
    6. int High = SafeRobber.plugin.getConfig().getStringList("DropLocation").size();
    7. int DPSelect = rint1.nextInt(High-Low) + Low;
    8. return DPSelect;
    9. }


    I'm trying to create a random number between 0 and the size of a list within the config
     
  2. Hasaanarshad Are you trying to get how many strings are in the list DropLocation?
     
  3. Offline

    user_90934786

    bwfcwalshy Yes and then I want to create a random number between 0 and the amount of strings in the list
     
  4. Offline

    fireblast709

    Hasaanarshad why the use of static? Also getConfig() is supposed to be a method, not a field.
     
  5. Offline

    user_90934786

    Im not using static in the code that generates the random number
     
  6. Offline

    Totom3

    Hasaanarshad Let me guess... Is this line 196 ?
    Code:java
    1. int High = SafeRobber.plugin.getConfig().getStringList("DropLocation").size();

    If it is, plugin is null, you forgot to initialize it.
     
  7. Offline

    mythbusterma

    Totom3 Hasaanarshad

    Instead of using that, perhaps you should learn why you shouldn't use statics (in this case). Either way, it's a simple null pointer.
     
Thread Status:
Not open for further replies.

Share This Page