Need help with Checkers

10-11  Source: Network gathering  Views:0 

Advertisement
Well i've been working on a checkers board and it worked fine until a while ago it showed the following error:
exception in thread "main" java.lang.NullPointerException
here's my code: (some parts are in spanish sorry :S)
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
public class JuegoGrafico extends JFrame {
    JLabel esp1 = new JLabel();
   JLabel esp2 = new JLabel();
   JLabel esp3 = new JLabel();
   JLabel esp4 = new JLabel();
   JLabel esp5 = new JLabel();
   JLabel esp6 = new JLabel();
   JLabel esp7 = new JLabel();
   JLabel esp8 = new JLabel();
   JLabel esp9 = new JLabel();
   JLabel esp10 = new JLabel();
   JLabel esp11 = new JLabel();
   JLabel esp12 = new JLabel();
   JLabel esp13 = new JLabel();
   JLabel esp14 = new JLabel();
   JLabel esp15 = new JLabel();
   JLabel esp16 = new JLabel();
   JLabel esp17 = new JLabel();
   JLabel esp18 = new JLabel();
   JLabel esp19 = new JLabel();
   JLabel esp20 = new JLabel();
   JLabel esp21 = new JLabel();
   JLabel esp22 = new JLabel();
   JLabel esp23 = new JLabel();
   JLabel esp24 = new JLabel();
   JLabel esp25 = new JLabel();
   JLabel esp26 = new JLabel();
   JLabel esp27 = new JLabel();
   JLabel esp28 = new JLabel();
   JLabel esp29 = new JLabel();
   JLabel esp30 = new JLabel();
   JLabel esp31 = new JLabel();
   JLabel esp32 = new JLabel();
   JLabel esp33 = new JLabel();
   JLabel esp34 = new JLabel();
   JLabel esp35 = new JLabel();
   JLabel esp36 = new JLabel();
   JLabel esp37 = new JLabel();
   JLabel esp38 = new JLabel();
   JLabel esp39 = new JLabel();
   JLabel esp40 = new JLabel();
   JLabel esp41 = new JLabel();
   JLabel esp42 = new JLabel();
   JLabel esp43 = new JLabel();
   JLabel esp44 = new JLabel();
   JLabel esp45 = new JLabel();
   JLabel esp46 = new JLabel();
   JLabel esp47 = new JLabel();
   JLabel esp48 = new JLabel();
   JLabel esp49 = new JLabel();
   JLabel esp50 = new JLabel();
   JLabel esp51 = new JLabel();
   JLabel esp52 = new JLabel();
   JLabel esp53 = new JLabel();
   JLabel esp54 = new JLabel();
   JLabel esp55 = new JLabel();
   JLabel esp56 = new JLabel();
   JLabel esp57 = new JLabel();
   JLabel esp58 = new JLabel();
   JLabel esp59 = new JLabel();
   JLabel esp60 = new JLabel();
   JLabel esp61 = new JLabel();
   JLabel esp62 = new JLabel();
   JLabel esp63 = new JLabel();
   JLabel esp64 = new JLabel();
   JLabel mensaje = new JLabel();
    private Juego juego;
    private int tipo;
    private int filaOrigen;
    private int columnaOrigen;
    private int filaDestino;
    private int columnaDestino;
    private boolean primerClick = true;
    private JLabel espOrigen;
    public JuegoGrafico() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        dibujarTableroInicial();
    public void dibujarTableroInicial(){
        Juego juego = new Juego();
        dibujarTablero();
    public void dibujarTablero(){
        mensaje.setText("Turno Rojo");
        String rey="";
        int[][] tablero = juego.getTablero();
        int esp = 1;
        for (int fila = 0; fila < tablero.length; fila++)  {
            for (int columna = 0; columna < tablero[fila].length; columna++)  {
                int estilo = tablero[fila][columna];
                Color fondo = null;
                Border  borde =BorderFactory.createLineBorder(Color.black,1);
                if (estilo == 1)
                        fondo = Color.black;
                else if (estilo == 0)
                        fondo = Color.white;                 
                else if (estilo == 2)
                        fondo = Color.red;  
                else if (estilo == 3)
                        fondo = Color.blue;   
                else if (estilo==4)
                   rey="   K";
                   fondo = Color.red;
                else if (estilo==5)
                   rey="   K";
                   fondo = Color.blue;
                JLabel queesp=null;
                switch(esp){
              case 1:
                             queesp = esp1;
                        break;
                        case 2:
                             queesp = esp2;
                        break;
                        case 3:
                             queesp = esp3;
                        break;
                        case 4:
                             queesp = esp4;
                        break;
                        case 5:
                             queesp = esp5;
                        break;
                        case 6:
                             queesp = esp6;
                        break;
                        case 7:
                             queesp = esp7;
                        break;
                        case 8:
                             queesp = esp8;
                        break;
                        case 9:
                             queesp = esp9;
                        break;
                        case 10:
                             queesp = esp10;
                        break;
                    case 11:
                             queesp = esp11;
                        break;
                        case 12:
                             queesp = esp12;
                        break;
                        case 13:
                             queesp = esp13;
                        break;
                        case 14:
                             queesp = esp14;
                        break;
                        case 15:
                             queesp = esp15;
                        break;
                        case 16:
                             queesp = esp16;
                        break;
                        case 17:
                             queesp = esp17;
                        break;
                        case 18:
                             queesp = esp18;
                        break;
                        case 19:
                             queesp = esp19;
                        break;
                        case 20:
                             queesp = esp20;
                        break;
                        case 21:
                             queesp = esp21;
                        break;
                        case 22:
                             queesp = esp22;
                        break;
                        case 23:
                             queesp = esp23;
                        break;
                        case 24:
                             queesp = esp24;
                        break;
                        case 25:
                             queesp = esp25;
                        break;
                        case 26:
                             queesp = esp26;
                        break;
                        case 27:
                             queesp = esp27;
                        break;
                        case 28:
                             queesp = esp28;
                        break;
                        case 29:
                             queesp = esp29;
                        break;
                        case 30:
                             queesp = esp30;
                        break;
                        case 31:
                             queesp = esp31;
                        break;
                        case 32:
                             queesp = esp32;
                        break;
                        case 33:
                             queesp = esp33;
                        break;
                        case 34:
                             queesp = esp34;
                        break;
                        case 35:
                             queesp = esp35;
                        break;
                        case 36:
                             queesp = esp36;
                        break;
                        case 37:
                             queesp = esp37;
                        break;
                        case 38:
                             queesp = esp38;
                        break;
                        case 39:
                             queesp = esp39;
                        break;
                        case 40:
                             queesp = esp40;
                        break;case 41:
                             queesp = esp41;
                        break;
                        case 42:
                             queesp = esp42;
                        break;
                        case 43:
                             queesp = esp43;
                        break;
                        case 44:
                             queesp = esp44;
                        break;
                        case 45:
                             queesp = esp45;
                        break;
                        case 46:
                             queesp = esp46;
                        break;
                        case 47:
                             queesp = esp47;
                        break;
                        case 48:
                             queesp = esp48;
                        break;
                        case 49:
                             queesp = esp49;
                        break;
                        case 50:
                             queesp = esp50;
                        break;
                        case 51:
                             queesp = esp51;
                        break;
                        case 52:
                             queesp = esp52;
                        break;
                        case 53:
                             queesp = esp53;
                        break;
                        case 54:
                             queesp = esp54;
                        break;
                        case 55:
                             queesp = esp55;
                        break;
                        case 56:
                             queesp = esp56;
                        break;
                        case 57:
                             queesp = esp57;
                        break;
                        case 58:
                             queesp = esp58;
                        break;
                        case 59:
                             queesp = esp59;
                        break;
                        case 60:
                             queesp = esp60;
                        break;
                        case 61:
                             queesp = esp61;
                        break;
                        case 62:
                             queesp = esp62;
                        break;
                        case 63:
                             queesp = esp63;
                        break;
                        case 64:
                             queesp = esp64;
                        break;
                cambiarPresentacionesp(queesp,fondo,borde,rey);
                esp++;
                rey="";
    public void cambiarPresentacionesp(JLabel esp, Color fondo, Border borde,String rey) {
        esp.setOpaque(true);
        esp.setBackground(fondo);
        esp.setBorder(borde);
        esp.setText(rey);
    private void jbInit() throws Exception {
        this.getContentPane().setLayout( null );
        this.setSize( new Dimension(400, 400) );
        this.setTitle( "Juego" );
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        esp1.setBounds(new Rectangle(60, 60, 30, 30));
        esp1.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp2.setBounds(new Rectangle(90, 60, 30, 30));
        esp2.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp3.setBounds(new Rectangle(120, 60, 30, 30));
        esp3.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp4.setBounds(new Rectangle(150, 60, 30, 30));
        esp4.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp5.setBounds(new Rectangle(180, 60, 30, 30));
        esp5.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp6.setBounds(new Rectangle(210, 60, 30, 30));
        esp6.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp7.setBounds(new Rectangle(240, 60, 30, 30));
        esp7.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp8.setBounds(new Rectangle(270, 60, 30, 30));
        esp8.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp9.setBounds(new Rectangle(60, 90, 30, 30));
        esp9.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp10.setBounds(new Rectangle(90, 90, 30, 30));
        esp10.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp11.setBounds(new Rectangle(120, 90, 30, 30));
        esp11.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp12.setBounds(new Rectangle(150, 90, 30, 30));
        esp12.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp13.setBounds(new Rectangle(180, 90, 30, 30));
        esp13.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp14.setBounds(new Rectangle(210, 90, 30, 30));
        esp14.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp15.setBounds(new Rectangle(240, 90, 30, 30));
        esp15.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp16.setBounds(new Rectangle(270, 90, 30, 30));
        esp16.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp17.setBounds(new Rectangle(60, 120, 30, 30));
        esp17.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp18.setBounds(new Rectangle(90, 120, 30, 30));
        esp18.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp19.setBounds(new Rectangle(120, 120, 30, 30));
        esp19.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp20.setBounds(new Rectangle(150, 120, 30, 30));
        esp20.setBorder(BorderFactory.createLineBorder(Color.black, 1)); 
        esp21.setBounds(new Rectangle(180, 120, 30, 30));
        esp21.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp22.setBounds(new Rectangle(210, 120, 30, 30));
        esp22.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp23.setBounds(new Rectangle(240, 120, 30, 30));
        esp23.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp24.setBounds(new Rectangle(270, 120, 30, 30));
        esp24.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp25.setBounds(new Rectangle(60, 150, 30, 30));
        esp25.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp26.setBounds(new Rectangle(90, 150, 30, 30));
        esp26.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp27.setBounds(new Rectangle(120, 150, 30, 30));
        esp27.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp28.setBounds(new Rectangle(150, 150, 30, 30));
        esp28.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp29.setBounds(new Rectangle(180, 150, 30, 30));
        esp29.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp30.setBounds(new Rectangle(210, 150, 30, 30));
        esp30.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp31.setBounds(new Rectangle(240, 150, 30, 30));
        esp31.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp32.setBounds(new Rectangle(270, 150, 30, 30));
        esp32.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp33.setBounds(new Rectangle(60, 180, 30, 30));
        esp33.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp34.setBounds(new Rectangle(90, 180, 30, 30));
        esp34.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp35.setBounds(new Rectangle(120, 180, 30, 30));
        esp35.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp36.setBounds(new Rectangle(150, 180, 30, 30));
        esp36.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp37.setBounds(new Rectangle(180, 180, 30, 30));
        esp37.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp38.setBounds(new Rectangle(210, 180, 30, 30));
        esp38.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp39.setBounds(new Rectangle(240, 180, 30, 30));
        esp39.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp40.setBounds(new Rectangle(270, 180, 30, 30));
        esp40.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp41.setBounds(new Rectangle(60, 210, 30, 30));
        esp41.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp42.setBounds(new Rectangle(90, 210, 30, 30));
        esp42.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp43.setBounds(new Rectangle(120, 210, 30, 30));
        esp43.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp44.setBounds(new Rectangle(150, 210, 30, 30));
        esp44.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp45.setBounds(new Rectangle(180, 210, 30, 30));
        esp45.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp46.setBounds(new Rectangle(210, 210, 30, 30));
        esp46.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp47.setBounds(new Rectangle(240, 210, 30, 30));
        esp47.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp48.setBounds(new Rectangle(270, 210, 30, 30));
        esp48.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp49.setBounds(new Rectangle(60, 240, 30, 30));
        esp49.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp50.setBounds(new Rectangle(90, 240, 30, 30));
        esp50.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp51.setBounds(new Rectangle(120, 240, 30, 30));
        esp51.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp52.setBounds(new Rectangle(150, 240, 30, 30));
        esp52.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp53.setBounds(new Rectangle(180, 240, 30, 30));
        esp53.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp54.setBounds(new Rectangle(210, 240, 30, 30));
        esp54.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp55.setBounds(new Rectangle(240, 240, 30, 30));
        esp55.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp56.setBounds(new Rectangle(270, 240, 30, 30));
        esp56.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp57.setBounds(new Rectangle(60, 270, 30, 30));
        esp57.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp58.setBounds(new Rectangle(90, 270, 30, 30));
        esp58.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp59.setBounds(new Rectangle(120, 270, 30, 30));
        esp59.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp60.setBounds(new Rectangle(150, 270, 30, 30));
        esp60.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp61.setBounds(new Rectangle(180, 270, 30, 30));
        esp61.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp62.setBounds(new Rectangle(210, 270, 30, 30));
        esp62.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp63.setBounds(new Rectangle(240, 270, 30, 30));
        esp63.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        esp64.setBounds(new Rectangle(270, 270, 30, 30));
        esp64.setBorder(BorderFactory.createLineBorder(Color.black, 1));
        mensaje.setBounds ((new Rectangle(140, 30, 100, 20)));
        esp2.addMouseListener(new MouseListener());   
        esp4.addMouseListener(new MouseListener());
        esp6.addMouseListener(new MouseListener());      
        esp8.addMouseListener(new MouseListener());       
        esp9.addMouseListener(new MouseListener());        
        esp11.addMouseListener(new MouseListener());      
        esp13.addMouseListener(new MouseListener());     
        esp15.addMouseListener(new MouseListener());      
        esp18.addMouseListener(new MouseListener());       
        esp20.addMouseListener(new MouseListener());
        esp22.addMouseListener(new MouseListener());
        esp24.addMouseListener(new MouseListener());
        esp25.addMouseListener(new MouseListener());
        esp27.addMouseListener(new MouseListener());
        esp29.addMouseListener(new MouseListener());
        esp31.addMouseListener(new MouseListener());
        esp34.addMouseListener(new MouseListener());
        esp36.addMouseListener(new MouseListener());
        esp38.addMouseListener(new MouseListener());   
        esp40.addMouseListener(new MouseListener());
        esp41.addMouseListener(new MouseListener());
        esp43.addMouseListener(new MouseListener()); 
        esp45.addMouseListener(new MouseListener());   
        esp47.addMouseListener(new MouseListener());
        esp50.addMouseListener(new MouseListener());  
        esp52.addMouseListener(new MouseListener());
        esp54.addMouseListener(new MouseListener());
        esp56.addMouseListener(new MouseListener());
        esp57.addMouseListener(new MouseListener());
        esp59.addMouseListener(new MouseListener());
        esp61.addMouseListener(new MouseListener());
        esp63.addMouseListener(new MouseListener());
        this.getContentPane().add(esp1, null);
        this.getContentPane().add(esp2, null);
        this.getContentPane().add(esp3, null);
        this.getContentPane().add(esp4, null);
        this.getContentPane().add(esp5, null);
        this.getContentPane().add(esp6, null);
        this.getContentPane().add(esp7, null);
        this.getContentPane().add(esp8, null);
        this.getContentPane().add(esp9, null);
        this.getContentPane().add(esp10, null);
        this.getContentPane().add(esp11, null);
        this.getContentPane().add(esp12, null);
        this.getContentPane().add(esp13, null);
        this.getContentPane().add(esp14, null);
        this.getContentPane().add(esp15, null);
        this.getContentPane().add(esp16, null);
        this.getContentPane().add(esp17, null);
        this.getContentPane().add(esp18, null);
        this.getContentPane().add(esp19, null);
        this.getContentPane().add(esp20, null);
        this.getContentPane().add(esp21, null);
        this.getContentPane().add(esp22, null);
        this.getContentPane().add(esp23, null);
        this.getContentPane().add(esp24, null);
        this.getContentPane().add(esp25, null);
        this.getContentPane().add(esp26, null);
        this.getContentPane().add(esp27, null);
        this.getContentPane().add(esp28, null);
        this.getContentPane().add(esp29, null);
        this.getContentPane().add(esp30, null);
        this.getContentPane().add(esp31, null);
        this.getContentPane().add(esp32, null);
        this.getContentPane().add(esp33, null);
        this.getContentPane().add(esp34, null);
        this.getContentPane().add(esp35, null);
        this.getContentPane().add(esp36, null);
        this.getContentPane().add(esp37, null);
        this.getContentPane().add(esp38, null);
        this.getContentPane().add(esp39, null);
        this.getContentPane().add(esp40, null);
        this.getContentPane().add(esp41, null);
        this.getContentPane().add(esp42, null);
        this.getContentPane().add(esp43, null);
        this.getContentPane().add(esp44, null);
        this.getContentPane().add(esp45, null);
        this.getContentPane().add(esp46, null);
        this.getContentPane().add(esp47, null);
        this.getContentPane().add(esp48, null);
        this.getContentPane().add(esp49, null);
        this.getContentPane().add(esp50, null);
        this.getContentPane().add(esp51, null);
        this.getContentPane().add(esp52, null);
        this.getContentPane().add(esp53, null);
        this.getContentPane().add(esp54, null);
        this.getContentPane().add(esp55, null);
        this.getContentPane().add(esp56, null);
        this.getContentPane().add(esp57, null);
        this.getContentPane().add(esp58, null);
        this.getContentPane().add(esp59, null);
        this.getContentPane().add(esp60, null);
        this.getContentPane().add(esp61, null);
        this.getContentPane().add(esp62, null);
        this.getContentPane().add(esp63, null);
        this.getContentPane().add(esp64, null);
        this.getContentPane().add(mensaje, null);
    public static void main(String[] args)
            JuegoGrafico pantalla = new JuegoGrafico();
            pantalla.setVisible(true);
    private class MouseListener extends MouseAdapter {
                    public void mouseClicked(MouseEvent e) {
                        JLabel esp = (JLabel)e.getSource();
                        int columna = (int)(esp.getBounds().getBounds().getX()/30);
                        int fila = (int)(esp.getBounds().getBounds().getY()/30);
                        if (primerClick == true){
                            filaOrigen = fila;
                            columnaOrigen = columna;
                            primerClick = false;
                            espOrigen = esp;
                            cambiarPresentacionesp(esp,Color.cyan,BorderFactory.createLineBorder(Color.black,1),"");
                        else{
                            filaDestino = fila;
                            columnaDestino = columna;
                            primerClick = true;
                            String movida = juego.mover(filaOrigen-1,columnaOrigen-1,filaDestino-1,columnaDestino-1);
                            dibujarTablero();
                            mensaje.setText(movida);
                            if(movida.equals("Gano Jugador Azul!")||movida.equals("Gano Jugador Rojo!")){
                                JOptionPane.showMessageDialog(getContentPane(),
                                          "Fin del Juego!!!!!",
                                          "Gracias por participar!", JOptionPane.INFORMATION_MESSAGE);
                                 dibujarTableroInicial();   
}and...
public class Juego {
    private int[][] tablero;
    private int turno=0;
    private int fichasr=12;
    private int fichasa=12;
    public Juego() {
        asignarConfiguracionTablero();
    public void asignarConfiguracionTablero(){
            int [][] tablero = { {0,2,0,2,0,2,0,2},
                                  {2,0,2,0,2,0,2,0},
                                  {0,2,0,2,0,2,0,2},
                                  {1,0,1,0,1,0,1,0},
                                  {0,1,0,1,0,1,0,1},
                                  {3,0,3,0,3,0,3,0},
                                  {0,3,0,3,0,3,0,3},
                                  {3,0,3,0,3,0,3,0},
    public String mover(int filaOrigen, int columnaOrigen, int filaDestino, int columnaDestino){
        String mensaje="";
               mensaje="Tiro Invalido";
               if (tablero[filaDestino-1][columnaDestino-1] == 1)
                     if (turno%2==0)
                       if (tablero[filaOrigen-1][columnaOrigen-1]==4)
                         if ((filaDestino-filaOrigen)==1)                 
                            if ((Math.abs(columnaOrigen-columnaDestino))==1)
                                   tablero[filaOrigen-1][columnaOrigen-1]=1;
                                   tablero[filaDestino-1][columnaDestino-1]=4;
                                   turno++;
                                   mensaje="Turno Azul";
                         if ((filaDestino-filaOrigen)==-1)
                          if ((Math.abs(columnaOrigen-columnaDestino))==1)
                                 tablero[filaOrigen-1][columnaOrigen-1]=1;
                                 tablero[filaDestino-1][columnaDestino-1]=4;
                                 turno++;
                                 mensaje="Turno Rojo";
                       if (tablero[filaOrigen-1][columnaOrigen-1]==2)
                         if ((filaDestino-filaOrigen)==1)                 
                            if ((Math.abs(columnaOrigen-columnaDestino))==1)
                                   tablero[filaOrigen-1][columnaOrigen-1]=1;
                                   tablero[filaDestino-1][columnaDestino-1]=2;
                                   turno++;
                                   mensaje="Turno Azul";
                         if ((filaDestino-filaOrigen)==2)
                            if ((Math.abs(columnaOrigen-columnaDestino))==2)
                               if (ComerR(filaOrigen, columnaOrigen, filaDestino, columnaDestino))
                                   tablero[filaOrigen-1][columnaOrigen-1]=1;
                                   tablero[filaDestino-1][columnaDestino-1]=2;
                                   if ((columnaOrigen-columnaDestino)<0)
                                      tablero[filaOrigen][columnaDestino-2]=1;
                                   else
                                      tablero[filaOrigen][columnaDestino]=1;
                                   turno++;
                                   mensaje="Turno Azul";
                     else
                        if (tablero[filaOrigen-1][columnaOrigen-1]==3)
                         if ((filaDestino-filaOrigen)==1)                 
                            if ((Math.abs(columnaOrigen-columnaDestino))==1)
                                   tablero[filaOrigen-1][columnaOrigen-1]=1;
                                   tablero[filaDestino-1][columnaDestino-1]=3;
                                   turno++;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
Diegogv wrote:
well... it just says that and...
at JuegoGrafico.dibujarTablero(JuegoGrafico.java:118)
at JuegoGrafico.dibujarTableroInicial(JuegoGrafico.java:112)
at JuegoGrafico.(init)(JuegoGrafico.java:107)
at JuegoGrafico.main(JuegoGrafico.java:660)Do you understand when a NPE can be thrown and do you know how to interpret the stacktrace?
A NPE will be thrown if you access an object while it is null.SomeObject someObject = null;
someObject.doSomething(); // Throws NPE.The stacktrace tells you what were the last executed methods and their line numbers. In this case, there is some object at line 118 of JuegoGrafico#dibujarTablero() which is apperently null and therefore caused the NPE. Fixing it is simple: just make sure that it is not null somehow or add a nullcheck.
Related articles