Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NullPointerException help needed

Status
Not open for further replies.

katenka5

ISP
Nov 30, 2001
15
US
I am getting a NullPointerException error and I cannot see where it is. It points to line 19 but I can't find what's wrong.


Code:
import java.awt.*;
import java.lang.Object;

public class Algorithm {

    public static void main (String args[]) {
        
    int deletedLines = 0;
    
    Label place[][];
                
    place = new Label[9][9];
    int counter=1;
    for (int i=0; i<9; i++)
    {
            for (int j=0; j<9; j++)
            {
            place[i][j].setText(&quot;aa&quot;);
            }
        }
    
        
    // HORIZONTAL LINES SEARCH

    for (int i=0; i<9; i++)
    {
            for (int j=0; j<5; j++)
        {
            if (place[i][j].getText() == place[i][j+1].getText())
            {
                counter++; //counter = 2 here
                if (place[i][j+1].getText() == place[i][j+counter].getText())
                {
                    counter++; //counter = 3 here
                    if (place[i][j+counter].getText() == place[i][j+counter+1].getText())
                    {
                        counter++; //counter = 4 here
                        if (place[i][j+counter].getText() == place[i][j+counter+1].getText())
                        {
                            counter++; //counter = 5 here
                            // call the DeleteFromBoard function here
                            deletedLines++;
                            System.out.println(deletedLines);                            
                        }
                        else counter=1;
                    }
                }
            }
        }
    }
    System.out.println(&quot;\n\n End of Program&quot;);
    
    
    }
    
}
 
You are never creating your Labels before trying to access them. Change your first for loop to look like this:
Code:
for (int i=0; i<9; i++) {
  for (int j=0; j<9; j++) {
    place[i][j] = new Label();
  }
}
 
Thanks Pete,

I have try to debug the code and find that the NullPointerException is most likely incurred by the InputStream and OutputStream, Since I found that when I try to close them , the same error appears, It seems that I have something wrong with the declaration of the In (inputStream) and Out (outputStream) . But I cannot spot it out as I just actually follow the procedures decribed in my textbook to create an inputStream and outputStream for socket TCP communication. I really can't figure it out ... :<

Thanks for note anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top