Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

illegal start of type & identifier expected

 
Kelly Frasure
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting 2 errors when I compile this program.
1. Pattern.java:18: illegal start of type
for (int col = 0; col >= 150; col += size)
^
2. Pattern.java:31: <identifier>
}
^
This is the code:
import java.awt.*;
public class Pattern
{

private final int WIDTH = 10;
private int col;
private final int YLOC = col * WIDTH;
for (int col = x1; col >= 150; col += size)
{
boolean which color;
which color = false;

for (int row = y1; r <= 150; r += size)
{
if (which color)
g.fillrect
g.filloval (row, col, size, size, color f1, color b1)
which color false;

else
which color true
}
}
 
ryan burgdorfer
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Both of your for loops initialize their variables to other variables, but those other variables aren't defined anywhere (x1 and y1)
2. Your boolean "which color" needs to be changed to "which_color", as variable names cannot have spaces
3. color f1 and b1 are not defined anywhere
4. You can't say "which_color false" (or true); you must use an =, as in "which_color = false"
5. You are missing the final closing brace for the class
These are mostly syntactical errors...there are other logical errors, but in the spirit of "nitpicking", we'll let you tackle these changes first then re-post your code
 
leo 9
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kally,
Rayan is right check out all his suggestions and there r lot of other syntax errors...
Re check the code
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kelly Frasure:
I am getting 2 errors when I compile this program.
1. Pattern.java:18: illegal start of type
for (int col = 0; col >= 150; col += size)
^
2. Pattern.java:31: <identifier>
}
^
This is the code:


The only things which can be defined inside a class and outside a method are static and instance variables, inner classes and static blocks. The compiler is looking for a method and it finds a for statement. So it complains.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic