aspose file tools*
The moose likes Beginning Java and the fly likes illegal start of type & identifier expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "illegal start of type & identifier expected" Watch "illegal start of type & identifier expected" New topic
Author

illegal start of type & identifier expected

Kelly Frasure
Greenhorn

Joined: Mar 03, 2001
Posts: 15
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

Joined: Jan 24, 2001
Posts: 219
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


<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
leo 9
Greenhorn

Joined: Mar 11, 2001
Posts: 3
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

Joined: Jul 22, 2000
Posts: 9052
    
  12
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: illegal start of type & identifier expected