943,898 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 3891
  • Java RSS
Jun 8th, 2009
0

Random.nextInt(); cannot find symbol

Expand Post »
Hi,
I'm having trouble with the following simple test program to extract 10 random numbers from 0 to 5.
java Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 34
Solved Threads: 2
Junior Poster in Training
freelancelote is offline Offline
88 posts
since Aug 2008
Jun 8th, 2009
1

Re: Random.nextInt(); cannot find symbol

Hi,
I'm having trouble with the following simple test program to extract 10 random numbers from 0 to 5.
java Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Jun 9th, 2009
0

Re: Random.nextInt(); cannot find symbol

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
Reputation Points: 34
Solved Threads: 2
Junior Poster in Training
freelancelote is offline Offline
88 posts
since Aug 2008
Jun 9th, 2009
1

Re: Random.nextInt(); cannot find symbol

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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Jun 9th, 2009
0

Re: Random.nextInt(); cannot find symbol

Strange. I use version JDK 1.6.0_13. Just downloaded last week.
Reputation Points: 34
Solved Threads: 2
Junior Poster in Training
freelancelote is offline Offline
88 posts
since Aug 2008
Jun 9th, 2009
0

Re: Random.nextInt(); cannot find symbol

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
Reputation Points: 34
Solved Threads: 2
Junior Poster in Training
freelancelote is offline Offline
88 posts
since Aug 2008
Jun 9th, 2009
1

Re: Random.nextInt(); cannot find symbol

Do you have somewhere another class named Random?
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,259 posts
since Dec 2007
Jun 9th, 2009
0

Re: Random.nextInt(); cannot find symbol

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
Reputation Points: 34
Solved Threads: 2
Junior Poster in Training
freelancelote is offline Offline
88 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Problems referencing an ARRAY of jtextfields in a custom focus traversal policy.
Next Thread in Java Forum Timeline: Sending files in socket problem///





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC