• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Error in Zoo.java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 8417
606
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic