Random.nextInt(); cannot find symbol

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2008
Posts: 87
Reputation: freelancelote is an unknown quantity at this point 
Solved Threads: 2
freelancelote's Avatar
freelancelote freelancelote is offline Offline
Junior Poster in Training

Random.nextInt(); cannot find symbol

 
0
  #1
Jun 8th, 2009
Hi,
I'm having trouble with the following simple test program to extract 10 random numbers from 0 to 5.
  1. import java.util.*;
  2.  
  3. public class TestRandom {
  4. public static void main(String[] args) {
  5. Random rand = new Random();
  6. for (int i = 0; i < 10; i++) {
  7. int j = rand.nextInt(5);
  8. System.out.println(j);
  9. }
  10. }
  11. }

Compiler says: cannot find method nextInt(int);

Sorry, but I can't really see the mistake. Any help is appreciated.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,819
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Random.nextInt(); cannot find symbol

 
1
  #2
Jun 8th, 2009
Originally Posted by freelancelote View Post
Hi,
I'm having trouble with the following simple test program to extract 10 random numbers from 0 to 5.
  1. import java.util.*;
  2.  
  3. public class TestRandom {
  4. public static void main(String[] args) {
  5. Random rand = new Random();
  6. for (int i = 0; i < 10; i++) {
  7. int j = rand.nextInt(5);
  8. System.out.println(j);
  9. }
  10. }
  11. }

Compiler says: cannot find method nextInt(int);

Sorry, but I can't really see the mistake. Any help is appreciated.

I don't see any mistake either. This compiled and ran perfectly for me.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 87
Reputation: freelancelote is an unknown quantity at this point 
Solved Threads: 2
freelancelote's Avatar
freelancelote freelancelote is offline Offline
Junior Poster in Training

Re: Random.nextInt(); cannot find symbol

 
0
  #3
Jun 9th, 2009
Thanks VernonDozier.
I don't understand then. My classpath is working fine and I can't think of any other problem.

Any ideas about where the mistake is?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Random.nextInt(); cannot find symbol

 
1
  #4
Jun 9th, 2009
I agree with VernonDozier, your code compiled and ran OK,
You should not be getting this problem unless and until you are using a Java compiler prior to release 1.2 (i.e a pre Java2 compiler cause nextInt(int) was added to the java.util.Random class in JDK 1.2)
Last edited by stephen84s; Jun 9th, 2009 at 5:47 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 87
Reputation: freelancelote is an unknown quantity at this point 
Solved Threads: 2
freelancelote's Avatar
freelancelote freelancelote is offline Offline
Junior Poster in Training

Re: Random.nextInt(); cannot find symbol

 
0
  #5
Jun 9th, 2009
Strange. I use version JDK 1.6.0_13. Just downloaded last week.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 87
Reputation: freelancelote is an unknown quantity at this point 
Solved Threads: 2
freelancelote's Avatar
freelancelote freelancelote is offline Offline
Junior Poster in Training

Re: Random.nextInt(); cannot find symbol

 
0
  #6
Jun 9th, 2009
Now it went even more strange...
The program works now for me too when using import java.util.Random; instead of import java.util.*; Anyone has seen that before, or has an idea why did that happend?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,677
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 226
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Random.nextInt(); cannot find symbol

 
1
  #7
Jun 9th, 2009
Do you have somewhere another class named Random?
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 87
Reputation: freelancelote is an unknown quantity at this point 
Solved Threads: 2
freelancelote's Avatar
freelancelote freelancelote is offline Offline
Junior Poster in Training

Re: Random.nextInt(); cannot find symbol

 
0
  #8
Jun 9th, 2009
Thanks javaAddict.
I believe you are right. I just tried to use another class under java.util (Arrays) and is working fine when using import java.util.*; .

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC