Hello,
I'm trying to make a simple program in Eclipse,
the code is allright exception made to
.public void run()
The error message is --Syntax error on token "void", @ expected
If anyone can help me I feel glad.
Niquinho
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello,
I'm trying to make a simple program in Eclipse,
the code is allright exception made to
.public void run()
The error message is --Syntax error on token "void", @ expected
If anyone can help me I feel glad.
Niquinho
Please post the code that generates the error, preferably as a stripped down version that demonstrates the problem (eg an SSCCE)
Ok,
The code is the following
public class tabuleiro extends GraphicsProgram { private static final int numrows = 8; private static final int numcolumns = 8; public static void main(String[] args) { public void run (){ int sqSize = getHeight() / numrows; for (int i = 0; i<numrows;i++); { for (int j = 0;j<numcolumns;j++); { int x = j*sqSize; int y = i*sqSize; Grect sq = new Grect (y,x,sqSize,sqSize); sq.setFilled (((i+j) % 2) !=0); add(sq); } } } } }
Thanks
A method: run() can not be defined inside of another method: main()
Add the ending } for one method's definition before starting to define a new method.
If you don't understand my answer, don't ignore it, ask a question.
Hello again,
I add a } before run() and the program continues give me errors.
I would like to have the code that works.public class tabuleiro extends GraphicsProgram { private static final int numrows = 8; private static final int numcolumns = 8; public static void main(String[] args) { }public void run (){ int sqSize = getHeight() / numrows; for (int i = 0; i<numrows;i++); { for (int j = 0;j<numcolumns;j++); { int x = j*sqSize; int y = i*sqSize; Grect sq = new Grect (y,x,sqSize,sqSize); sq.setFilled (((i+j) % 2) !=0); add(sq); } } } } }
Thanks.
Last edited by Norm; December 18th, 2012 at 06:23 PM. Reason: java= removed from code tag
When you get errors, you need to copy the full text of the error messages and post them here.the program continues give me errors.
If you don't understand my answer, don't ignore it, ask a question.
Ok, the error message is:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at tabuleiro.main(tabuleiro.java:6)
You need to get the error message from the compiler that says what the error is.
What you posted does not say what the error is. It just says: Unresolved compilation problem:
and gives a line number: 6
I don't know what the error is without a message that describes the error.
If you don't understand my answer, don't ignore it, ask a question.
Error messages: GraphicsProgram cannot be resolved to a type; The method getHeight() is undefined for the type tabuleiro; j cannot be resolved to a variable; i cannot be resolved to a variable; ;Multiple markers at this line- Grect cannot be resolved to a type; Multiple markers at this line- i cannot be resolved to a variable.
I know is a lot of errors, but I'm trying to improve.
Do you need an import statement for the compiler to find GraphicsProgram?
The rest of the errors are very hard to solve because the error message does not show where the error is or what the source line was with the error.
Here is a sample compiler error message:
This is what you need to post if you want someone to help you solve the compiler errors.TestSorts.java:138: cannot find symbol symbol : variable var location: class TestSorts var = 2; ^
If you don't understand my answer, don't ignore it, ask a question.
Hello again,
Import statement for the compiler fo find GraphicsProgram?
Do some research about how to use the import statement.
http://docs.oracle.com/javase/tutori...e/usepkgs.html
Where is the GraphicsProgram class defined?
If you don't understand my answer, don't ignore it, ask a question.
I will make some research, in order to understand where the GraphicsProgram is defined.
Thanks, for the link.