Results 1 to 7 of 7

Thread: Compiling error

  1. #1
    lawksalih's Avatar
    lawksalih is offline Member
    Join Date
    Jan 2008
    Location
    WWW
    Posts
    4
    Rep Power
    0

    Exclamation Compiling error

    Good-day everyone! I am new to this forum and as you can see, I have a "new-to-java" question:

    Here is the code [class Die]:

    Java Code:
    class Die {
    
    	//Data Members
    
    	//the largest number on a die
    	private static final int MAX_NUMBER = 6;
    
    	//the smallest number on a die
    	private static final int MIN_NUMBER = 1;
    
    	//To represent a die that is not yet rolled
    	private static final int NO_NUMBER = 0;
    
    	private int number;
    
    	//Constructor
    	public Die() {
    		number = NO_NUMBER;
    
    	}
    
    	//Rolls the die
    	public void roll() {
    		number = (int) (Math.floor(Math.random() *
    							(MAX_NUMBER - MIN_NUMBER + 1)) + MIN_NUMBER);
    
    	}
    
    	//Returns the number on this die
    	public int getNumber() {
    		return number;
    	}
    }
    and here is [class RollDice]:


    Java Code:
    class RollDice {
    
    	//Simulates the rolling of three dice
    	public static void main(String[] args) {
    
    		Die one, two, three
    		one = new Die( );
    		two = new Die( );
    		three = new Die( );
    
    		one.roll();
    		two.roll();
    		three.roll();
    
    		System.out.println("Results are " + one.getNumber( ) + "	" +
    											two.getNumber( ) + "	" +
    											three.getNumber( ) );
    	}
    
    }
    Anytime I try to compile the code of the RollDice class, I get an error and it says:

    D:\FILE\RollDice.java:7: ';' expected
    one = new Die( );
    ^
    1 error

    Tool completed with exit code 1
    Die class compiles successfully but when I try to run it, I get the following error message:

    Exception in thread "main" java.lang.NoSUchMethodError: main

    Press any key to continue...
    Your help will be greatly appreciated.
    Attached Thumbnails Attached Thumbnails Compiling error-javaerror.jpg  
    Last edited by lawksalih; 01-28-2008 at 10:16 PM.

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    8

    Default Missing semicolon

    Welcome lawksalih

    You've got a missing semicolon. Only a syntax error. :p
    Java Code:
    class RollDice {
    
    	//Simulates the rolling of three dice
    	public static void main(String[] args) {
    
    		Die one, two, three[B][COLOR="Red"];[/COLOR][/B]
    		one = new Die( );
    		two = new Die( );
    		three = new Die( );
    
    		one.roll();
    		two.roll();
    		three.roll();
    
    		System.out.println("Results are " + one.getNumber( ) + "	" +
    											two.getNumber( ) + "	" +
    											three.getNumber( ) );
    	}
    
    }
    It should work now. ;)
    Last edited by tim; 01-28-2008 at 10:41 PM.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    lawksalih's Avatar
    lawksalih is offline Member
    Join Date
    Jan 2008
    Location
    WWW
    Posts
    4
    Rep Power
    0

    Default

    Grrrrrrrrrrrrrrrrrrrr.

    Thanks very much.
    Last edited by lawksalih; 01-28-2008 at 10:46 PM.

  4. #4
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    8

    Default

    Quote Originally Posted by lawksalih View Post
    Grrrrrrrrrrrrrrrrrrrr
    Strange. :confused: Do you have another problem or question?
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  5. #5
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    lawksalih, make sure you actually try to understand the error messages. Because i mean, the error clearly states that there was a missing semicolon

    D:\FILE\RollDice.java:7: ';' expected

    It even tells you the line where the error occured (line 7).

    It is important to be able to solve these things.

  6. #6
    lawksalih's Avatar
    lawksalih is offline Member
    Join Date
    Jan 2008
    Location
    WWW
    Posts
    4
    Rep Power
    0

    Default

    It was my fault for not paying attention. But your help is greatly appreciated.

    Best,

    Lawk

  7. #7
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    Quote Originally Posted by lawksalih View Post
    It was my fault for not paying attention. But your help is greatly appreciated.

    Best,

    Lawk
    It's cool man, just from now on, see if you can understand error messages, and if not, just post em here and ask what they mean and how to resolve them. Just a few that i think are common: (not word for word)


    Java Code:
    ExampleClass e = new ExampleClass();
    Error:
    ExampleClass cannot be resolved to a type:
    This means one of two things:
    1) You didn't import ExampleClass
    2) ExampleClass does not exist

    -----------Error 2----------------
    Java Code:
    ExampleClass e = new ExampleClass(5);
    Error:
    Cannot find symbol constructor ExampleClass(int a)
    This means that you are using a constructor that does not exist
    In this case, the constructor ExampleClass(int a) does not exist in the
    ExampleClass class.
    (The same holds true for methods)

    ----------Error 3-----------------
    Java Code:
    if(a == b))
    //do something
    Error:
    Syntax error on token ')', delete this token
    This obviously means that you have an extra parenthesis.


    There are many many more you will come across, but these are 3 syntax errors. Eventually, you'll get to the point where you never worry about compile time errors, because you understand the error messages immediately and can fix them. It's logic errors you're gonna hate.

Similar Threads

  1. compiling trouble
    By capacitator in forum CLDC and MIDP
    Replies: 4
    Last Post: 06-10-2008, 11:12 PM
  2. I have 3 errors after compiling
    By coco in forum JDBC
    Replies: 2
    Last Post: 10-18-2007, 10:32 AM
  3. Error during compiling
    By boy22 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 03:42 AM
  4. problems when compiling
    By valery in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 08:35 PM
  5. Error while compiling
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2007, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •