Hi guys,
I got a problem with my Programm after adding a new Class in my Tic_Tac_Toe version...I tryed to use a method of the clas KI_Test1 ( which is a very simple "AI"). The class before without static works.
After changing everythin in static, because my main method is static, the compiler doesn't show me a mistake, but if I want to start it.It says "java.lang.NullPointerException". I know that it has to do with my used array in my main class, but I cannot find it...
The error appears in the first line of my class "KI_Test1" method "Vergleichen():
if(Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][0].farbe.equals(Punkt))
but what is wrong about this? o.O
Here's the code of my new Class:

import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.io.*;
import javax.swing.*;
import java.awt.*;

public class KI_Test1
{
    // instance variables - replace the example below with your own

    private static final long serialVersionUID = 1L;
        private static JButton button1;
        private static JButton button2;
        private static JButton button3;
        private static JButton button4;
        private static JButton button5;
        private static JButton button6;
        private static JButton button7;
        private static JButton button8;
        private static JButton button9;
        private static JButton button10;
        private JPanel panelButton;
        private JLabel oben;
        private JLabel anzeige;
        private JLabel creator;
        private static int e=0;
        private static int farbe3=0;
        private static int farbe4=0;
        private static Kreis Kaestchen1 [][];
        private static String Punkt;
        private static int x;
        private static int y;
        private static int d;
        private Rechteck [] linie;
        private static String farbe1;
        private static String farbe2;
        private String information1;
        private String information2;
    /**
     * Constructor for objects of class KI_Test1
     */
    public KI_Test1()
    {
        // initialise instance variables
        x = 0;
         farbe1="rot";
         farbe2="blau";
         d=0;
        Kaestchen1= new Kreis[5][5];
        new Rechteck("schwarz");
        new Kreis("schwarz", 190, (x+1)*50, (y+1)*50);
        linie = new Rechteck [10];
        //linie [0]= new Rechteck (String farbe1, int xPos, int yPos, int breite1, int hoehe1);
        linie [1]= new Rechteck ("gelb",1,100,300,2);//mitte oben
        linie [2]= new Rechteck ("gelb",1,200,300,2);//mitte unten
        linie [1]= new Rechteck ("gelb",100,1,2,300);//mitte Links
        linie [2]= new Rechteck ("gelb",200,1,2,300);//mitte Rechts
        linie [3]= new Rechteck ("gelb",1,1,2,300);// Rand Links
        linie [3]= new Rechteck ("gelb",300,1,2,300);//Rand Rechts
        linie [3]= new Rechteck ("gelb",1,300,300,2);//Rand Unten
        linie [3]= new Rechteck ("gelb",1,1,300,2);
        Kaestchen1 [3][3]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [0][1]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [0][2]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [1][0]=new Kreis("schwarz", 90, 150, 150);//Alle Kreise erstellen
        Kaestchen1 [1][1]=new Kreis("schwarz", 90, 150, 150);// und in die Mitte des Feldes platzieren 
        Kaestchen1 [1][2]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][0]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][1]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][2]=new Kreis("schwarz", 90, 150, 150);//

    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public static void Vergleich()throws IOException  {
        Punkt="rot";
        if(Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][0].farbe.equals(Punkt))
            {   
            x=2 ;
            y=0 ;
            }
        else{    
        if(    Kaestchen1[1][0].farbe.equals(Punkt)&& Kaestchen1[2][0].farbe.equals(Punkt))// waagerecht
            {
            x=3 ;
            y=3 ;
            }
            else{
        if(    Kaestchen1[0][1].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt))
            {
            x= 2;
            y= 1;
            }
            else{
        if(    Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[2][1].farbe.equals(Punkt))// waagerecht
            {
            x=0 ;
            y=1 ;
            }
            else{
        if(    Kaestchen1[0][2].farbe.equals(Punkt)&& Kaestchen1[1][2].farbe.equals(Punkt))
            {
            x=2 ;
            y=2 ;
            }
            else{
        if(    Kaestchen1[1][2].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt))// waagerecht
            {
            x= 0;
            y= 2;
            }
            else{
        if(    Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[0][1].farbe.equals(Punkt))
            {
            x= 0;
            y= 2;
            }
            else{
        if( Kaestchen1[0][1].farbe.equals(Punkt)&& Kaestchen1[0][2].farbe.equals(Punkt))// senkrecht
            {
            x=3 ;
            y=3 ; 
            }
            else{
        if( Kaestchen1[1][0].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt))
            {
            x=1 ;
            y=2 ;
            } 
            else{
        if(    Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[1][2].farbe.equals(Punkt))// senkrecht
            {
            x=1 ;
            y=0 ;
            }
            else{
        if(Kaestchen1[2][0].farbe.equals(Punkt)&& Kaestchen1[2][1].farbe.equals(Punkt))
           { 
           x=2 ;
           y=2 ; 
           }
            else{
        if(    Kaestchen1[2][1].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt))// senkrecht
           { 
           x=2 ;
           y=0 ;
           }
            else{
        if(Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt))
            {
           x=2 ;
           y=2 ;
            }
            else{
         if(Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt))// diagonal
            {
            x=3 ;
            y=3 ;
            }
            else{
        if(Kaestchen1[2][0].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt))
           { 
            x=0 ;
            y=2 ;
            }
            else{
        if(    Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[0][2].farbe.equals(Punkt))  // diagonal
                {
            x=2 ;
            y=0 ;
        }
        else{
     Punkt="blau";
        if(Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][0].farbe.equals(Punkt))
            {   
            x=2 ;
            y=0 ;
            }
        else{    
        if(    Kaestchen1[1][0].farbe.equals(Punkt)&& Kaestchen1[2][0].farbe.equals(Punkt))// waagerecht
            {
            x=3 ;
            y=3 ;
            }
            else{
        if(    Kaestchen1[0][1].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt))
            {
            x= 2;
            y= 1;
            }
            else{
        if(    Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[2][1].farbe.equals(Punkt))// waagerecht
            {
            x=0 ;
            y=1 ;
            }
            else{
        if(    Kaestchen1[0][2].farbe.equals(Punkt)&& Kaestchen1[1][2].farbe.equals(Punkt))
            {
            x=2 ;
            y=2 ;
            }
            else{
        if(    Kaestchen1[1][2].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt))// waagerecht
            {
            x= 0;
            y= 2;
            }
            else{
        if(    Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[0][1].farbe.equals(Punkt))
            {
            x= 0;
            y= 2;
            }
            else{
        if( Kaestchen1[0][1].farbe.equals(Punkt)&& Kaestchen1[0][2].farbe.equals(Punkt))// senkrecht
            {
            x=3 ;
            y=3 ; 
            }
            else{
        if( Kaestchen1[1][0].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt))
            {
            x=1 ;
            y=2 ;
            } 
            else{
        if(    Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[1][2].farbe.equals(Punkt))// senkrecht
            {
            x=1 ;
            y=0 ;
            }
            else{
        if(Kaestchen1[2][0].farbe.equals(Punkt)&& Kaestchen1[2][1].farbe.equals(Punkt))
           { 
           x=2 ;
           y=2 ; 
           }
            else{
        if(    Kaestchen1[2][1].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt))// senkrecht
           { 
           x=2 ;
           y=0 ;
           }
            else{
        if(Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt))
            {
           x=2 ;
           y=2 ;
            }
            else{
        if(Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt))// diagonal
            {
            x=3 ;
            y=3 ;
            }
            else{
        if(Kaestchen1[2][0].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt))
           { 
            x=0 ;
            y=2 ;
            }
            else{
        if(    Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[0][2].farbe.equals(Punkt))  // diagonal
                {
            x=2 ;
            y=0 ;
        }   

    else{                    
        double temp1=Math.random();
        double temp2=Math.random();
        System.out.println(temp1);
        System.out.println(temp2);
        if(temp1<=(0.33))
        {
        System.out.println("Die Temp1 ist kleiner als 1/3");
        x=0;
        }
        else {
            if (temp1>=(0.33) && temp1<=(0.66))
            {
            System.out.println("Die Temp1 ist kleiner als 2/3");
            x=1;
            }
            else {
                System.out.println("Die Temp1 ist kleiner/gleich als 1");
                x=2;
            }

    }

    if(temp2<=0.33)
        {
        System.out.println("Die Temp2 ist kleiner als 1/3");
        y=0;
        }
        else {
            if (temp2>=(0.33) && temp2<=(0.66))
            {
            System.out.println("Die Temp2 ist kleiner als 2/3");
            y=1;
            }
            else {
                System.out.println("Die Temp2 ist kleiner/gleich als 1");
                y=2;
            }
       }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

    KI_Spielzug();
     }


    private static void KI_Spielzug() throws IOException
    {
        if(x==0 && y==0)       
        {  
          Vergleich();
        }      
   else{
            Punkt=farbe2;
             if ( Kaestchen1[y][x].farbe.equals("schwarz"))
                {
                    if ( x==3 && y==3)
                    {
                       Kaestchen1 [3][3]=new Kreis(Punkt, 190, 4, 4);
                    }
                    else{
                        if (y==0 && x==1)
                        {
                            Kaestchen1 [0][1]=new Kreis(Punkt, 190, 103, 4);

                        }
                        else {
                            if (y==0&& x==2) 
                            {
                                Kaestchen1 [0][2]=new Kreis(Punkt, 190, 203, 4);
                            }
                            else {
                                if (y==1&&x==0)
                                {
                                    Kaestchen1 [1][0]=new Kreis(Punkt, 190, 4, 103);
                                }
                                else{
                                    if (y==1 && x==1)
                                    {
                                        Kaestchen1 [1][1]=new Kreis(Punkt, 190, 103, 103);
                                    }
                                    else{
                                        if( y==1 && x==2)
                                        {
                                            Kaestchen1 [1][2]=new Kreis(Punkt, 190, 203, 103);
                                        }
                                        else{
                                            if(y==2 && x==0){
                                                Kaestchen1 [2][0]=new Kreis(Punkt, 190, 4, 203);
                                            }
                                            else {
                                                if (y==2 && x==1)
                                                {
                                                    Kaestchen1 [2][1]=new Kreis(Punkt, 190, 103, 203);
                                                }
                                                else {
                                                   if (y==2 && x==2){
                                                    Kaestchen1 [2][2]=new Kreis(Punkt, 190, 203, 203);
                                                }
                                            }
                                            }
                                        }
                                    }
                                }
                            }
                        }
      }
      e++;
   }
   else {
                    System.out.println (" Dieses Feld ist schon belegt");
                    System.out.println(" Wählen sie nochmal ein Feld");
                    Vergleich();
                }
   if (
        Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][0].farbe.equals(Punkt)&& Kaestchen1[2][0].farbe.equals(Punkt)||// waagerecht
        Kaestchen1[0][1].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[2][1].farbe.equals(Punkt)||// waagerecht
        Kaestchen1[0][2].farbe.equals(Punkt)&& Kaestchen1[1][2].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt)||// waagerecht
        Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[0][1].farbe.equals(Punkt)&& Kaestchen1[0][2].farbe.equals(Punkt)||// senkrecht
        Kaestchen1[1][0].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[1][2].farbe.equals(Punkt)||// senkrecht
        Kaestchen1[2][0].farbe.equals(Punkt)&& Kaestchen1[2][1].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt)||// senkrecht
        Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt)||// diagonal
        Kaestchen1[2][0].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[0][2].farbe.equals(Punkt)  // diagonal
       )
               {
           if(Punkt.equals("rot"))
        {
            farbe3++;
        }
        else {
        if( Punkt.equals("blau"))
        {
        farbe4++;
        }
        }
         System.out.println("Spieler1 " + " hat " + farbe3+ " Punkte.");
         System.out.println("Spieler2 "+ " hat " + farbe4+ " Punkte.");
        }
            else 
        {
            if (d>=9)
            {
                System.out.println(" Unentschieden");
            }
            else {
                   }
    }
                  }
        Tic_Tac_Toe_V6.addButtonListener(null);
                }


            }

And here is my main class

import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import java.io.IOException;
import java.io.*;
import javax.swing.*;
import java.awt.*;
 public   class  Tic_Tac_Toe_V6 extends JFrame implements ActionListener
{


   private static final long serialVersionUID = 2L;
    private static JButton button1;
    private static JButton button2;
    private static JButton button3;
    private static JButton button4;
    private static JButton button5;
    private static JButton button6;
    private static JButton button7;
    private static JButton button8;
    private static JButton button9;
    private static JButton button10;
    private JPanel panelButton;
    private JLabel oben;
    private JLabel anzeige;
    private JLabel creator;
    private static int e=0;
    private static int farbe3=0;
    private static int farbe4=0;
    private static Kreis Kaestchen1 [][];
    private static String Punkt;
    private static int x;
    private static int y;
    private static int d;
    private Rechteck [] linie;
    private static int farbe1;
    private String information1;
    private String information2;

    public  Tic_Tac_Toe_V6() throws IOException {  
        //MOUSELISTENER 
         super("Fenster");
        setLocation(300,300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Das BorderLayout ist mal das erste - später fügen wir noch ein GridLayout im Westen hinzu
        getContentPane().setLayout(new BorderLayout(12,12));  

        //Buttons erzeugen
        button1 = new JButton("Feld  0/0");
        button2 = new JButton("Feld  0/1");
        button3 = new JButton("Feld  0/2");
        button4 = new JButton("Feld  1/0");
        button5 = new JButton("Feld  1/1");
        button6 = new JButton("Feld  1/2");
        button7 = new JButton("Feld  2/0");
        button8 = new JButton("Feld  2/1");
        button9 = new JButton("Feld  2/2");
        button10 = new JButton(" Neues Spiel");
        //Panels erzeugen auf einem GridLayout
        panelButton = new JPanel(new GridLayout(9,1));

        //Auf Panel Buttons packen
        panelButton.add(button1);
        panelButton.add(button2);
        panelButton.add(button3);
        panelButton.add(button4);
        panelButton.add(button5);
        panelButton.add(button6);
        panelButton.add(button7);
        panelButton.add(button8);
        panelButton.add(button9);
        panelButton.add(button10);

        //Listener für Buttons
        addButtonListener(button1);
        addButtonListener(button2);
        addButtonListener(button3);
        addButtonListener(button4);
        addButtonListener(button5);
        addButtonListener(button6);
        addButtonListener(button7);
        addButtonListener(button8);
        addButtonListener(button9);
        addButtonListener(button10);
         //Labels erzeugen
        oben = new JLabel("Jan Berens");
        //Label zentrieren
        oben.setHorizontalAlignment(JLabel.CENTER); 
        anzeige = new JLabel("Button klicken");
        creator = new JLabel("Jan Berens");

        //Labels auf Frame packen (direkt auf das BorderLayout)
        getContentPane().add(BorderLayout.NORTH, oben);
        getContentPane().add(anzeige);

        //Panels auf Frame packen (das panelButton hat ein GridLayout, dass jetzt in den WestBereich des BorderLayouts kommt)
        getContentPane().add(BorderLayout.WEST, panelButton);

        pack();
        setVisible(true);
        //MOUSELISTENER 


        d=0;
        Kaestchen1= new Kreis[5][5];
        new Rechteck("schwarz");
        new Kreis("schwarz", 190, (x+1)*50, (y+1)*50);
        linie = new Rechteck [10];
        //linie [0]= new Rechteck (String farbe1, int xPos, int yPos, int breite1, int hoehe1);
        linie [1]= new Rechteck ("gelb",1,100,300,2);//mitte oben
        linie [2]= new Rechteck ("gelb",1,200,300,2);//mitte unten
        linie [1]= new Rechteck ("gelb",100,1,2,300);//mitte Links
        linie [2]= new Rechteck ("gelb",200,1,2,300);//mitte Rechts
        linie [3]= new Rechteck ("gelb",1,1,2,300);// Rand Links
        linie [3]= new Rechteck ("gelb",300,1,2,300);//Rand Rechts
        linie [3]= new Rechteck ("gelb",1,300,300,2);//Rand Unten
        linie [3]= new Rechteck ("gelb",1,1,300,2);
        Kaestchen1 [3][3]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [0][1]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [0][2]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [1][0]=new Kreis("schwarz", 90, 150, 150);//Alle Kreise erstellen
        Kaestchen1 [1][1]=new Kreis("schwarz", 90, 150, 150);// und in die Mitte des Feldes platzieren 
        Kaestchen1 [1][2]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][0]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][1]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][2]=new Kreis("schwarz", 90, 150, 150);//

    }

    public static void main(String[] args)
    {

    }
    public void actionPerformed2(ActionEvent e) { 
    StackTraceElement d = Thread.currentThread().getStackTrace()[2];
    System.out.println( d.getMethodName() );
        if ((e.getSource().equals(button1)))
        {
            System.out.println("Button1 geklickt!"); 
            x=3;
            y=3;
        } 
        else {
         if ((e.getSource().equals(button2)))
        {
            System.out.println("Button2 geklickt!"); 
            x=0;
            y=1;
        } 
        else {
             if ((e.getSource().equals(button3)))
        {
            System.out.println("Button3 geklickt!"); 
            x=0;
            y=2;
        } 
        else {
             if ((e.getSource().equals(button4)))
        {
            System.out.println("Button4 geklickt!"); 
            x=1;
            y=0;
        } 
        else {
             if ((e.getSource().equals(button5)))
        {
           System.out.println("Button5 geklickt!"); 
            x=1;
            y=1;
        } 
        else {
             if ((e.getSource().equals(button6)))
        {
            System.out.println("Button6 geklickt!"); 
            x=1;
            y=2;
        } 
        else {
             if ((e.getSource().equals(button7)))
        {
            System.out.println("Button7 geklickt!"); 
            x=2;
            y=0;
        } 
        else {
             if ((e.getSource().equals(button8)))
        {
            System.out.println("Button8 geklickt!"); 
            x=2;
            y=1;
        } 
        else {
             if ((e.getSource().equals(button9)))
        {
            System.out.println("Button9 geklickt!"); 
            x=2;
            y=2;
        } 
        else {
       } 
}
}
}
}
}
}
}
}



    }  static void addButtonListener(JButton b) throws IOException
    {
        b.addActionListener(new ActionListener() 
        { 

            public void actionPerformed(ActionEvent ae) 
            { 
              String farbe1="rot";
              String farbe2="blau";
      if (e==0||e==2 ||e==4||e==6||e==8||e==10||e==12||e==14||e==16||e==18||e==20||e==22||e==24||e==26 )
      {
          Punkt=farbe1;
        }
       else {
        Punkt=farbe2;
        }
                Object obj=ae.getSource();
                if (obj== button1)
                {
                System.out.println ("Button1");
                x=3;
                y=3;
            }
                else{
                    if (obj== button2)
                    {
                    System.out.println ("Button2");
                    x=0;
                    y=1;
                    }
                    else {
                        if (obj== button3)
                        {
                        System.out.println ("Button3");
                        x=0;
                        y=2;
                        }
                        else {
                        if (obj== button4)
                    {
                     System.out.println ("Button4");
                     x=1;
                     y=0;
                    }
                    else {
                        if(obj== button5)
                        {
                         System.out.println ("Button5");
                        x=1;
                        y=1;
                        }
                        else {
                        if (obj== button6)
                        {
                             System.out.println ("Button6");
                             x=1;
                             y=2;
                            }
                        else{
                            if (obj== button7)
                            {
                             System.out.println ("Button7");
                             x=2;
                             y=0;
                            }
                            else {
                            if(obj== button8)
                            {
                             System.out.println ("Button8");
                             x=2;
                             y=1;
                            }
                            else {
                            if (obj== button9)
                            {
                             System.out.println ("Button9");
                             x=2;
                             y=2;
                            }
                           }
                         }
                     }
                  }
             }
         }
     }
   }
////
    if ( Kaestchen1[y][x].farbe.equals("schwarz"))
                {
                    if ( x==3 && y==3)
                    {
                       Kaestchen1 [3][3]=new Kreis(Punkt, 190, 4, 4);
                    }
                    else{
                        if (y==0 && x==1)
                        {
                            Kaestchen1 [0][1]=new Kreis(Punkt, 190, 103, 4);

                        }
                        else {
                            if (y==0&& x==2) 
                            {
                                Kaestchen1 [0][2]=new Kreis(Punkt, 190, 203, 4);
                            }
                            else {
                                if (y==1&&x==0)
                                {
                                    Kaestchen1 [1][0]=new Kreis(Punkt, 190, 4, 103);
                                }
                                else{
                                    if (y==1 && x==1)
                                    {
                                        Kaestchen1 [1][1]=new Kreis(Punkt, 190, 103, 103);
                                    }
                                    else{
                                        if( y==1 && x==2)
                                        {
                                            Kaestchen1 [1][2]=new Kreis(Punkt, 190, 203, 103);
                                        }
                                        else{
                                            if(y==2 && x==0){
                                                Kaestchen1 [2][0]=new Kreis(Punkt, 190, 4, 203);
                                            }
                                            else {
                                                if (y==2 && x==1)
                                                {
                                                    Kaestchen1 [2][1]=new Kreis(Punkt, 190, 103, 203);
                                                }
                                                else {
                                                   if (y==2 && x==2){
                                                    Kaestchen1 [2][2]=new Kreis(Punkt, 190, 203, 203);
                                                }
                                            }
                                            }
                                        }
                                    }
                                }
                            }
                        }
      }
e++;
}
else {
                    System.out.println (" Dieses Feld ist schon belegt");
                    System.out.println(" Wählen sie nochmal ein Feld");
                }
 if (
        Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][0].farbe.equals(Punkt)&& Kaestchen1[2][0].farbe.equals(Punkt)||// waagerecht
        Kaestchen1[0][1].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[2][1].farbe.equals(Punkt)||// waagerecht
        Kaestchen1[0][2].farbe.equals(Punkt)&& Kaestchen1[1][2].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt)||// waagerecht
        Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[0][1].farbe.equals(Punkt)&& Kaestchen1[0][2].farbe.equals(Punkt)||// senkrecht
        Kaestchen1[1][0].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[1][2].farbe.equals(Punkt)||// senkrecht
        Kaestchen1[2][0].farbe.equals(Punkt)&& Kaestchen1[2][1].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt)||// senkrecht
        Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[2][2].farbe.equals(Punkt)||// diagonal
        Kaestchen1[2][0].farbe.equals(Punkt)&& Kaestchen1[1][1].farbe.equals(Punkt)&& Kaestchen1[0][2].farbe.equals(Punkt)  // diagonal
       )
               {
           if(Punkt.equals("rot"))
        {
            farbe3++;
        }
        else {
        if( Punkt.equals("blau"))
        {
        farbe4++;
        }
        }
         System.out.println("Spieler1 " + " hat " + farbe3+ " Punkte.");
         System.out.println("Spieler2 "+ " hat " + farbe4+ " Punkte.");
        }
            else 
        {
            if (d>=9)
            {
                System.out.println(" Unentschieden");
            }
            else {
                   }
    }
       if( obj==button10) { 


           Kaestchen1 [3][3]=new Kreis("schwarz", 190, 4, 4);
           Kaestchen1 [0][1]=new Kreis("schwarz", 190, 103, 4);
           Kaestchen1 [0][2]=new Kreis("schwarz", 190, 203, 4);
           Kaestchen1 [1][0]=new Kreis("schwarz", 190, 4, 103);
           Kaestchen1 [1][1]=new Kreis("schwarz", 190, 103, 103);
           Kaestchen1 [1][2]=new Kreis("schwarz", 190, 203, 103);
           Kaestchen1 [2][0]=new Kreis("schwarz", 190, 4, 203);
           Kaestchen1 [2][1]=new Kreis("schwarz", 190, 103, 203);
           Kaestchen1 [2][2]=new Kreis("schwarz", 190, 203, 203);
           d=0;
           e=0;          
        }
 }

        });

    KI_Test1.Vergleich();
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {

    }

   }

Print each of the variables/expressions on that line to see which is null.

this is the complet error massage:

java.lang.NullPointerException
    at KI_Test1.Vergleich(KI_Test1.java:95)
    at Tic_Tac_Toe_V6.addButtonListener(Tic_Tac_Toe_V6.java:424)
    at Tic_Tac_Toe_V6.<init>(Tic_Tac_Toe_V6.java:87)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at bluej.runtime.ExecServer$3.run(ExecServer.java:740)

what is the line at sun.refelct....? is that the Action listener?
Here are the lines of my "own" written code wich are mentioned in the error massage:
1st:

 if(Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][0].farbe.equals(Punkt))
            {   
            x=2 ;
            y=0 ;
            }
        else{ 

2nd:

if (d>=9)
            {
                System.out.println(" Unentschieden");
            }
            else {}

3rd:(in the Constructor)
addButtonListener(button1);

the thing is that in other versions of my programm works and i have nothing changed at these, except the 1st. This part is totally new. Might it be that the arrays in the diffrent classes cann't compared because the path where they are saved are diffrent?

You instantiate an instance from Kreis class. Later on, you attempt to access its member variable farbe which may be null. How is your Kreis class implemented?

Kaestchen1 [3][3]=new Kreis("schwarz", 90, 150, 150);
Ah, yes sry that my programm is on german^^
farbe means colour -> String and it shouldn't be able that is is null because in the counstructor
                      it's 
                    predefined. ( schwarz is black, the values behind is the position where this 
                    circle (Kreis)is and it's size.
My double arry of Kreis are the nine circles of my tic_tac_toe game which are back at the beginning of the game and if you press the button of each array it get's a diffrent colour.

And I think I know where the problem might be:
I compare the arrays like :


    if(Kaestchen1[3][3].farbe.equals(Punkt)&& Kaestchen1[1][0].farbe.equals(Punkt))


and these arrays are created in the Class KI_Test1 (which means AI_Test^^) and in the class of Tic_Tac_Toe_V6 and they have a diffrent sourcepath so they might compare the false pairs of arrays.
So the classes are only compare their own arrays.
Might that the problem?

I must be mad to have waded through all that code in German, but...

Lines 64... you call addButtonListener.
The last line of that method calls KI_Test1.Vergleich();
Vergleich() accesses elements of the Kaestchen1 array
then, finally, around line 119 you initialise the elements of Kaestchen1

... so when you call KI_Test1.Vergleich(); from addButtonListener the array is still unitialised, so you get null pointers.

Wow thank you very much :)
But I'm still a bloddy beginner at Java, so what you mean is that I have to initialise the array in my constructor at the beginning?

Unless the array initialisation depends on something else that has to be done first, then the earlier you initialise it the better, and the constructor is an ideal place to do it.
In general, the same thing is true of all the variables in a program... as far as possible you should ensure that they are initialised where they are declared, or initialised in a constructor. It's not always possible - eg you may need input from the user to set the size of an array - but in those cases you need to be extra careful to make sure those variables are never used before they are initialised.

Ah ok but haven't I done that?

public KI_Test1()
    {

        x = 0;
         farbe1="rot";
         farbe2="blau";
         d=0;
        Kaestchen1= new Kreis[5][5];
        new Rechteck("schwarz");
        new Kreis("schwarz", 190, (x+1)*50, (y+1)*50);
        linie = new Rechteck [10];
        //linie [0]= new Rechteck (String farbe1, int xPos, int yPos, int breite1, int hoehe1);
        linie [1]= new Rechteck ("gelb",1,100,300,2);
        linie [2]= new Rechteck ("gelb",1,200,300,2);
        linie [1]= new Rechteck ("gelb",100,1,2,300);
        linie [2]= new Rechteck ("gelb",200,1,2,300);
        linie [3]= new Rechteck ("gelb",1,1,2,300);
        linie [3]= new Rechteck ("gelb",300,1,2,300);
        linie [3]= new Rechteck ("gelb",1,300,300,2);
        linie [3]= new Rechteck ("gelb",1,1,300,2);
        Kaestchen1 [3][3]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [0][1]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [0][2]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [1][0]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [1][1]=new Kreis("schwarz", 90, 150, 150);// 
        Kaestchen1 [1][2]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][0]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][1]=new Kreis("schwarz", 90, 150, 150);//
        Kaestchen1 [2][2]=new Kreis("schwarz", 90, 150, 150);//
    }

And by the way I have the same contructer in my other Versions and there is no NullException

I don't have time to follow your code completely, but it looks to me like you don't ever create new KI_Test1, so that constructor is never called. (The Vergleich method is static, so it doesn't need an instance.)

SO static methods don't care about the contructor? o.O

Ahhh - I just read a bit more of the code and saw that all your variables are static, so everything I previously said about constructors is irrelevant!
Static vars and methods belong to the class itself, and have no access to instance methods or variables. You can use static members without ever creating an instance of the class. Constructors are specifically used to initialise instances when they are created, and that's all.

With all static variables you just need to be careful to initialise before you use. In this case that's as simple as putting things in the right order in your main method.

ps: Java is an object-oriented language, and so instances and instance methods and variables are what it's all about. Static methods and variables are only used in specific cirumstances. What you're doing here is not necessarily wrong, but it's not the way you will be doing things in future.

Yes now I had put the constructor in my main methode (only the part with the arrays) but now i got a new error massage....
java.lang.NoClassDefFoundError:
grafik/Zeichenfenster (grafik is a package and in it there is the Class Zeichenfenster "Drawing Window")
The thing is I got this package from my teacher....

If you want to use the Zeichenfenster class then you need to:
place the grafik package somewhere that's in the classpath
import the graphik package at the start of your program

I think I'm going to go crazy soon.... :'(
The 1st Problems are solved now no error massage with the arrays now hopfully....
but there are error massages about "Zeichenfenster" wich hadn't been there before.
And I hadn't changed anything at this class-.-

java.lang.NullPointerException
    at grafik.Zeichenfenster.farbeAufloesen(Zeichenfenster.java:330)
    at grafik.Zeichenfenster.zeichnen(Zeichenfenster.java:276)
    at Kreis.zeichnen(Kreis.java:157)
    at Kreis.<init>(Kreis.java:91)
    at KI_Test1.KI_Spielzug(KI_Test1.java:393)
    at KI_Test1.Vergleich(KI_Test1.java:338)
    at KI_Test1.KI_Spielzug(KI_Test1.java:346)
    at KI_Test1.Vergleich(KI_Test1.java:338)
    at Tic_Tac_Toe_V6.addButtonListener(Tic_Tac_Toe_V6.java:427)
    at Tic_Tac_Toe_V6.<init>(Tic_Tac_Toe_V6.java:111)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at bluej.runtime.ExecServer$3.run(ExecServer.java:740)

OK, deep breaths.
Check the lines in question, add print statements to see which variable on that line is null. Once yo have identified the problem, trace the code backwards to see where it started.

So I should work like every Error line:

System.out.println(this);

?

Suppose you have a line
a = b.toString() + array[i];
then you would try
System.out.println("b is " + b + " array[i] is " + array[i]);
ie print the specific variables that are used on that line.

OK. I did it with the print code I posted. In static methods it doesn't work so I was only able to prove the first 3or 4 Error massages and I only get normaly values and their address, but in the last line of my Terminal stands always " Exception occureed."
So should I try it with the debugger? or is it in this thing "useless"

Printing "this" is useless with static code/vars because it refers to the current instance, and there isn't one. You can print the specific variables as I illustrated in previus post. You can defintely find the null value that way.

(I'll be leaving soon, so don't worry if I stop posting until tomorrow)

Ok. I done that in your verion of printing.
There are a lot of null values....
at this line

private void zeichnen() {
        if (wirdAngezeigt) {

            Zeichenfenster zeichenfenster = Zeichenfenster.zeichenfensterGeben();
            System.out.println(this+ farbe + xPosition+ yPosition+ breite+ hoehe);
            zeichenfenster.zeichnen(this, farbe , new Ellipse2D.Double(xPosition, yPosition, breite, hoehe));
        }
    }  

zeichnen means draw.
But I looked in the constructor and the main class and I had initialized all of them....

So should I make the xPosition and yPosition maybe as a public acces value and as static?

Randomly making stuff static is leading you in the wrong direction. You need to use more print statements to follow those variables back to where they came from. You'll probably find either (1) the initialisation code wasn't called, even if you think it was, or (2) you have multiple variables with the same name

OK. There is somewhere a problem with the value farbe (color) I initialised it in every constructor which is excisting and in every method and it is still null?!? How can it be?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.