| | |
Random.nextInt(); cannot find symbol
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hi,
I'm having trouble with the following simple test program to extract 10 random numbers from 0 to 5.
Compiler says: cannot find method nextInt(int);
Sorry, but I can't really see the mistake. Any help is appreciated.
I'm having trouble with the following simple test program to extract 10 random numbers from 0 to 5.
java Syntax (Toggle Plain Text)
import java.util.*; public class TestRandom { public static void main(String[] args) { Random rand = new Random(); for (int i = 0; i < 10; i++) { int j = rand.nextInt(5); System.out.println(j); } } }
Compiler says: cannot find method nextInt(int);
Sorry, but I can't really see the mistake. Any help is appreciated.
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
•
•
•
•
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)
import java.util.*; public class TestRandom { public static void main(String[] args) { Random rand = new Random(); for (int i = 0; i < 10; i++) { int j = rand.nextInt(5); System.out.println(j); } } }
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.
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)
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 ?"
"How to ask questions the smart way ?"
Do you have somewhere another class named Random?
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- using the setText() method - getting error cannot find symbol (Java)
- Help Java error message: cannot find symbol (Java)
- cannot find symbol error message (Java)
- Cannot find symbol, Constructor... (Java)
- Cannot find symbol (Java)
- Another "cannot find symbol" compiling error (Java)
Other Threads in the Java Forum
- Previous Thread: Problems referencing an ARRAY of jtextfields in a custom focus traversal policy.
- Next Thread: Sending files in socket problem///
| Thread Tools | Search this Thread |
2dgraphics android api apple applet application arguments array arrays automation banking binary binarytree bluetooth capture chat chatprogramusingobjects class classes client code color component count database derby design eclipse eclipsedevelopment encryption error event exception fractal game givemetehcodez graphics gridlayout gui html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list loop macintosh map method methods midlethttpconnection mobile netbeans newbie object os print printing problem producer program programming project projectideas read recursion reference replaysolutions ria scanner screen server set size sms sort sourcelabs sql stop string swing threads transforms tree ui unicode validation windows






