Error on Vector in Java

0

I would appreciate if someone can help me with the following error:

  

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException   at folder.ConfigTeclado.guardaConfig (ConfigTeclado.java:91)

The code (only the parts where I use it) is as follows:

public class ConfigTeclado extends JPanel implements ActionListener,KeyListener{
    private Vector teclas = new Vector();
    public void keyPressed(KeyEvent e){ }

    public void keyReleased(KeyEvent e){
        Boolean ver=true;
        if(!ban){
            for(int i=0;i<b.length && ver;i++){ 
                 if(b[i].getLabel().equals(e.getKeyText(e.getExtendedKeyCode())))
                ver=false;  
            }
            teclas.add(e.getKeyCode());        
            if(ver){
                a.setLabel(e.getKeyText(e.getExtendedKeyCode()));             
                ban=true;              
            }        
        }
    }

    public void guardaConfig(){ 
        bd.inicializar();             
        bd.actualizarConfiguracion("UP", (int)teclas.elementAt(0));
        bd.actualizarConfiguracion("DOWN", (int)teclas.elementAt(1));
        bd.actualizarConfiguracion("LEFT", (int)teclas.elementAt(2));
        bd.actualizarConfiguracion("RIGHT", (int)teclas.elementAt(3));
        bd.cerrar();
    }
}

Thank you very much!

    
asked by Valentina 01.08.2018 в 20:26
source

1 answer

2

It is possible that bd (in saveConfig ()) has null value or does not exist, generally a nullPointerException is given when you try to change a value or use a method of something that is not really initialized or has not been assigned a value to despite having been referenced to some type of data or object.

Even if it's incoherent because you're just trying to do that here:

bd.inicializar();

The issue is if bd, at that time, was the object that it required to be able to call the initialize method or not.

    
answered by 01.08.2018 в 20:38