• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error in Zoo.java  RSS feed

 
Yousif Hafedh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am new to this site, so if this question has been asked before, which it probably has, please direct me to the appropriate forum.

I've done very little coding in my life but recently started studying Java 8 seriously. I bought the OCA Java SE 8 Programmer 1 study guide (I have bought more basic books), and I am at the part of Writing a main() method.

I created a new file called Zoo.java, as it asked, and I typed in the following code:

$ javac Zoo.java
$ java Zoo

I get the error message, 'Random cannot be resolved to a type
Random cannot be resolved to a type

at ImportExample.main(ImportExample.java:5)'

It told me, if I got error messages, to check that I have installed a JDK, which I have, and to add it to the PATH, which I don't know what that means. It also suggested I come to this website. So here I am. What am I doing wrong?

Thank you for any answers in advance.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you got the error message after the first instruction
javac Zoo.java?
If you did, then you have installed Java® correctly and set the PATH correctly. That means there is an error in your code. There is something wrong with something called Random. By Random, do you mean this? If so, how did you import the Random class? I think incorrect importing is the most likely cause for that error message. Please show us your import declarations and also the line 5 which the tool is complaining about.

And welcome to the Ranch
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case you got confused of multiple instructions given by Cambell Ritchie, please show us all *.java files you have for this application and their contents. Don't forget to UseCodeTags (<- link to click on) when you post code, it would make your code more readable.

And welcome to the Ranch again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!