This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Math.random() symbol not found error? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Math.random() symbol not found error?" Watch "Math.random() symbol not found error?" New topic
Author

Math.random() symbol not found error?

thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 113


When I compile the above program in jcreator IDE, there are no errors and there is succesful compilation and when i write it in TextPad and compile it from the command line, I get a compile error which says Math.random() not found

What is my mistake here? please help.


on job hunt
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3785
    
    1

Do you have a Math class of your own hanging around? That's one possible cause. The compiler could be trying to use that instead of java.lang.Math, and if your class doesn't have a random() method it will fail with that error.
thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 113
Matthew Brown wrote:Do you have a Math class of your own hanging around? That's one possible cause. The compiler could be trying to use that instead of java.lang.Math, and if your class doesn't have a random() method it will fail with that error.


Bang on!!

there was a Math.class in the classes folder. deleted it and got it working. thank you
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32595
    
    4
Probably better to work out how to use a java.util.Random object. It’s much more versatile than Math.random().
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3785
    
    1

Campbell Ritchie wrote:Probably better to work out how to use a java.util.Random object. It’s much more versatile than Math.random().

But if you do, watch out for the same problem again since you've got a Random class!

(It's generally a good idea to avoid having classes with the same name as core Java classes, especially commonly used ones.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math.random() symbol not found error?
 
Similar Threads
JSTL: $Math.random()
How to get a random number
round()
implicit downcast possible?
private