Ok, so. I ordered a book on Java (Sams teach yourself java in 21 days) a week ago, and it came in just yesterday. I am working on the first example code, and I keep getting this error when I try to compile the main code:
C:\VolcanoApplication.java:5: error: cannot find symbol
VolcanoRobot dante = new VolcanoRobot();
^
symbol: class VolcanoRobot
location: class VolcanoApplication
C:\VolcanoApplication.java:5: error: cannot find symbol
VolcanoRobot dante = new VolcanoRobot();
^symbol: class VolcanoRobot
location: class VolcanoApplication
And the main code Im trying to compile is:
public class VolcanoApplication
{
public static void main(String[] arguments)
{
VolcanoRobot dante = new VolcanoRobot();
dante.status = "exploring";
dante.speed = 2;
dante.temperature = 510;
dante.showAttributes();
System.out.println("Increasting speed to 3.");
dante.speed = 3;
dante.showAttributes();
System.out.println("Changing temperature to 670.");
dante.temperature = 670;
dante.showAttributes();
System.out.println("Checking the temperature.");
dante.checkTemperature();
dante.showAttributes();
}
}
and the VolcanoRobot.java file:
public class VolcanoRobot
{
String status;
int speed;
float temperature;
void checkTemperature()
{
if(temperature > 660)
{
status = "returning home";
speed = 5;
}
}
void showAttributes()
{
System.out.println("Status: " + status);
System.out.println("Speed: " + speed);
System.out.println("Temperature: " + temperature);
}
}
I am unable to get javac to run anywhere in command prompt (I’m running xp) so I navigate to where my javac.exe is (C:\Program Files\Java\jdk1.7.0_03\bin) and compile VolcanoApplication from there (VolcanoApplication is found on the root of C:)
When I just type Java anywhere I get the menu, but not javac. I declared the path and classpath variables, and yet it doesn’t work. any suggestions?
Your best bet is to make
javacwork from any directory by going into the environment variables and changing yourPATHso it includesC:\Program Files\jdk1.7.0_03\bin.Once you’ve done that, in a command prompt typing
javacanywhere should work.The reason
javacisn’t finding theVolcanoRobot.javafile is that it’s not in the path thatjavacsearches for source files. By default, that path includes the current directory, so if youcdto the directory containingVolcanoApplication.javaandVolcanoRobot.java, then…should do it. If it doesn’t, add
-cp .:You should then be able to run it via
…or
Update: Since my main workstation is Linux-based, I hadn’t done this under Windows 7 (used to do it all the time with Windows XP) and so I got to wondering whether there was something special about it. Doesn’t look like there is. I installed the JDK on my Windows 7 box and didn’t have any trouble using it. Here’s exactly what I did:
javacand pressed Enter, just to make sure I didn’t have one installed I didn’t remember. I got the usual “…is not recognized as an internal or external command” error.Path.bindirectory, which was atC:\Program Files\Java\jdk1.7.0_03\bin.;) (note: not a colon, and with no spaces around it), and then pasted the path from the clipboard.javacand pressed Enter. I got thejavachelp listing.C:\tmp\j).Typed:
…and pressed Enter. I got no errors.
Typed:
…and pressed Enter. It worked just fine, I got the output I’d expect from looking at the source files.
So there’s no problem doing this on Windows 7. Perhaps what I did above will be helpful to you.