Results 1 to 5 of 5
  1. #1
    Javasubbu is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default error compiling program for Random Numbers

    Hi,

    I am compiling the following code,

    Java Code:
    public class Random{
    	public static void main(String[] args) {
    	Random ran = new Random();
    	int number = ran.nextInt();
    	System.out.println(number);
    	}							
    }
    And I get the following error while compiling it...

    Java Code:
    C:\Subbu\Java>javac Random.java
    Random.java:4: error: cannot find symbol
            int number = ran.nextInt();
                            ^
      symbol:   method nextInt()
      location: variable ran of type Random
    1 error
    Can you help ?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,373
    Blog Entries
    7
    Rep Power
    25

    Default Re: error compiling program for Random Numbers

    Your class Random has nothing to do with the Random class you find in the SE distribution; rename your class.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    Javasubbu is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: error compiling program for Random Numbers

    Thanks, but still the same...

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,373
    Blog Entries
    7
    Rep Power
    25

    Default Re: error compiling program for Random Numbers

    Do you still have a stray Random.class somewhere? Delete it and import the correct Random class (it's in the java.util package).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  5. #5
    Javasubbu is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: error compiling program for Random Numbers

    Perfect, Thanks! For some reason none of my books mentioned it... :(

Similar Threads

  1. Is Random() Only For Numbers?
    By Salamander in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 11:02 AM
  2. Java program problem.. Arrays.. Random Numbers
    By Chewart in forum New To Java
    Replies: 16
    Last Post: 11-16-2009, 11:21 PM
  3. Replies: 8
    Last Post: 04-19-2009, 05:50 PM
  4. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 PM
  5. random numbers
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 03:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •