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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NullPointerException help

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;);
	
	
	}
	
}
 
I think that you need to post your request to the &quot;Java forum&quot; in order to get an answer for that.
 
// HORIZONTAL LINES SEARCH

for (int i=0; i<9; i++)
{
counter++; //counter can = 5 here too- You should reset it by each loop
for (int j=0; j<5; j++)
{
if (place[j].getText() == place[j+1].getText())
{
counter++; //counter = 2 here
if (place[j+1].getText() == place[j+counter].getText())
{
counter++; //counter = 3 here
if (place[j+counter].getText() == place[j+counter+1].getText())
{
counter++; //counter = 4 here
if (place[j+counter].getText() ==
place[j+counter+1].getText())
{
counter++; //counter = 5 here
// call the DeleteFromBoard function here
deletedLines++;
System.out.println(deletedLines);
}
else counter=1;
}
}
}
}
}
 
I mean this thing:
// HORIZONTAL LINES SEARCH

for (int i=0; i<9; i++)
{
//counter can = 5 here too - You should reset it by each loop
for (int j=0; j<5; j++)
{
if (place[j].getText() == place[j+1].getText())
{
counter++; //counter = 2 here
if (place[j+1].getText() == place[j+counter].getText())
{
counter++; //counter = 3 here
if (place[j+counter].getText() == place[j+counter+1].getText())
{
counter++; //counter = 4 here
if (place[j+counter].getText() ==
place[j+counter+1].getText())
{
counter++; //counter = 5 here
// call the DeleteFromBoard function here
deletedLines++;
System.out.println(deletedLines);
}
else counter=1;
}
}
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top