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.

Results 1 to 13 of 13

Thread: public void run () error message

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default public void run () error message

    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


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: public void run () error message

    Please post the code that generates the error, preferably as a stripped down version that demonstrates the problem (eg an SSCCE)

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: public void run () error message

    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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: public void run () error message

    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.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: public void run () error message

    Hello again,

    I add a } before run() and the program continues give me errors.
    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); }
    			    }
    			}
     
     
    	}
     
    }
    I would like to have the code that works.
    Thanks.
    Last edited by Norm; December 18th, 2012 at 06:23 PM. Reason: java= removed from code tag

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: public void run () error message

    the program continues give me errors.
    When you get errors, you need to copy the full text of the error messages and post them here.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: public void run () error message

    Ok, the error message is:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at tabuleiro.main(tabuleiro.java:6)

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: public void run () error message

    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.

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: public void run () error message

    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.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: public void run () error message

    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:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    This is what you need to post if you want someone to help you solve the compiler errors.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: public void run () error message

    Hello again,

    Import statement for the compiler fo find GraphicsProgram?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: public void run () error message

    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.

  13. #13
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: public void run () error message

    I will make some research, in order to understand where the GraphicsProgram is defined.
    Thanks, for the link.

Similar Threads

  1. Why my void run method cannot be execute?
    By 90th century in forum Threads
    Replies: 2
    Last Post: March 30th, 2012, 12:09 PM
  2. How can you get the compiler to run more than one public class?
    By tai8 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 19th, 2012, 04:27 PM
  3. public static void main(NewMember Mr_Bukkake){ }
    By Mr. Bukkake in forum Member Introductions
    Replies: 2
    Last Post: October 13th, 2011, 07:29 AM
  4. [SOLVED] Is "Public void closeFile()" a problem in the program for AS-Level computing project
    By muffin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 5th, 2009, 09:12 PM