• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Math.random() symbol not found error?

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
sinatra roger
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably better to work out how to use a java.util.Random object. It’s much more versatile than Math.random().
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic