JavaNullPointerexception problem in Array

1

my problem is that I have:

  

'JavaNullPointerException' in 'kits [k] =   plugin.getPropertiesKit (). getString (b); '

I have this code,

        int numberKits = 2;
        int n = 1;
        int k = 0;
        int m = 1;

        //Bucle for para imprimir en el chat el nombre de todos los kits de propertiesKits.yml
        for(int i=1; i <= numberKits; i++){
            String a = "Kits.kit"+n+".name";
            sender.sendMessage(plugin.getPropertiesKit().getString(a));
            //Aqui acab de imprimir los nombres de los kits

            //Bucle for que almacena en el array kits el nombre de todos los kits de propertiesKits.yml

            for(int j=1; j <= numberKits; j++){
                String b = "Kits.kit"+m+".name";
                kits[k] = plugin.getPropertiesKit().getString(b);
                sender.sendMessage(kits[k]);
                m++;
            }
            //Aqui acaba el for de kits
            n++;
        }
    
asked by bruno Diaz martin 15.08.2016 в 18:18
source

2 answers

0

This is a common problem

'JavaNullPointerException' in 'kits[k] = plugin.getPropertiesKit().getString(b);'

can be caused by several causes

  • fix kits is not initialized.
  • plugin is null the method
  • .getPropertiesKit() gets a value null.

You must add more information for example your class plugin and verify declare and initialize the array kits[] .

    
answered by 15.08.2016 / 18:24
source
0

Analyzing your code there are so many things that may be causing the problem, you may have to place all the pieces to be able to help you better. I mention some of the ones I see.

Assuming everything is initialized correctly. The problem would be in the initialization of your path variables i and j , remember that in Java the first element of an array is in position 0 not in position 1 and that the last element is in position n - 1 not in position n . For your code you would always be leaving without evaluating the first element of the array and trying to evaluate an element more than what you have in the array.

In your code you always rewrite the value of kits[k] because k is always 0, you do not increase it; and we are assuming that kits has been correctly initialized.

Place your stackTrace to have a better view of the problem, if none of the above points solve your problem.

    
answered by 15.08.2016 в 21:46