Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-28-2008, 10:13 PM
lawksalih's Avatar
Member
 
Join Date: Jan 2008
Location: WWW
Posts: 4
lawksalih is on a distinguished road
Send a message via MSN to lawksalih Send a message via Yahoo to lawksalih
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]:

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]:


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:

Quote:
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:

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

Press any key to continue...
Your help will be greatly appreciated.
Attached Images
File Type: jpg javaError.jpg (62.0 KB, 5 views)

Last edited by lawksalih : 01-28-2008 at 10:16 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-28-2008, 10:38 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Missing semicolon
Welcome lawksalih

You've got a missing semicolon. Only a syntax error.
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( ) ); } }
It should work now.
__________________
If your ship has not come in yet then build a lighthouse.

Last edited by tim : 01-28-2008 at 10:41 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-28-2008, 10:40 PM
lawksalih's Avatar
Member
 
Join Date: Jan 2008
Location: WWW
Posts: 4
lawksalih is on a distinguished road
Send a message via MSN to lawksalih Send a message via Yahoo to lawksalih
Grrrrrrrrrrrrrrrrrrrr.

Thanks very much.

Last edited by lawksalih : 01-28-2008 at 10:46 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-28-2008, 10:43 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Quote:
Originally Posted by lawksalih View Post
Grrrrrrrrrrrrrrrrrrrr
Strange. Do you have another problem or question?
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-29-2008, 07:04 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-29-2008, 03:52 PM
lawksalih's Avatar
Member
 
Join Date: Jan 2008
Location: WWW
Posts: 4
lawksalih is on a distinguished road
Send a message via MSN to lawksalih Send a message via Yahoo to lawksalih
It was my fault for not paying attention. But your help is greatly appreciated.

Best,

Lawk
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-29-2008, 08:26 PM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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)


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----------------
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-----------------
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.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling trouble capacitator CLDC and MIDP 4 06-10-2008 11:12 PM
I have 3 errors after compiling coco Database 2 10-18-2007 10:32 AM
Error during compiling boy22 New To Java 2 08-03-2007 03:42 AM
problems when compiling valery New To Java 2 07-25-2007 08:35 PM
Error while compiling ai_2007 Advanced Java 1 07-01-2007 12:37 PM


All times are GMT +3. The time now is 10:44 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org