Forums Register Login

illegal start of type & identifier expected

+Pie Number of slices to send: Send
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
}
}
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Kally,
Rayan is right check out all his suggestions and there r lot of other syntax errors...
Re check the code
+Pie Number of slices to send: Send
 

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.

WARNING! Do not activate jet boots indoors or you will see a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1241 times.
Similar Threads
Block Sliding Puzzle
Drawing Problems with JPanel /Jframe need optimize solution.
Swing--JTable in JInternalFrame
I'm sure I'm doing something very dumb.... why can't I see my JLabel?
Bidimensional array to GUI?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:47:35.