aspose file tools*
The moose likes Beginning Java and the fly likes Can't set path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can Watch "Can New topic
Author

Can't set path

Ben Lall
Greenhorn

Joined: May 25, 2012
Posts: 3
I recently let my little cousin (unsupervised) play around on my computer, and he did whatever it is little children do and got a bunch of viruses that made it so that I had to reset my computer. After waving a heartfelt goodbye to all of my songs and stuff, I put my computer back to the factory defaults.

Well now, whenever I try to run anything to do with java, a command prompt appears for a split second and disappears, and the program won't run. The error displayed is "Error: Could not find or load main class (Directory to where the program is)" So I figured I just need to fix my path, right?

So I went to my environment variables, and under System Variables, I did what the FAQ said: I made a JAVA_HOME variable and set it to "C:\Program Files\Java\Jdk1.7.0_04\" and then added to path: ";%JAVA_HOME%\bin\" and restarted my computer, but even still, nothing will run.

I don't know if this is the right place, because everything seems to do with programming, but this seems like a nice community, so if you could at the least direct me to somewhere I should put it, that would be great!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Welcome to the Ranch

We have an FAQ about the same subject. I presume you have already seen it? Like most things in computing, you can do this several different ways. The Oracle instructions tell you how to set a PATH without referring to JAVA_HOME.
I presume you have not set a user JAVA_HOME and a system PATH; that doesn’t work.
What happens when you write echo %PATH% at the command line? Do you get sensible responses when you write java -version and javac -version at the command line? If the java version is significantly less than for javac, tell us.

The error about not finding main class sounds more like an incorrect CLASSPATH. Do the same and view your CLASSPATH variable. Is there anything in it which looks real (QuickTime has a reputation for creating a CLASSPATH and messing the rest of your settings up)? If so, add dot-semicolon .; to the beginning (left) of the classpath. Otherwise write the CLASSPATH on a piece of paper in case you ever need to restore it, and delete it altogether. Classpath entries to the jdk folder etc., can be deleted.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
The new PATH entry to JAVA_HOME\bin should be at the left of the PATH, by the way.
Ben Lall
Greenhorn

Joined: May 25, 2012
Posts: 3
when I type echo %PATH% I get:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Ben>echo %path%
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\windows\system32;C:\wi
ndows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Pr
ogram Files\Java\jdk1.7.0_04\\bin;


And for the other two:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Ben>java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

C:\Users\Ben>javac -version
javac 1.7.0_04

Also, there was no CLASSPATH, but I made one and set it to be the same thing for path and then restarted, but still nothing will work.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
If there was no classpath, then you could only make things worse by setting it. You ought to delete whatever you set.
You appear to have a correct PATH, working correctly if you are getting 1.7...

Can you get a Hello World program to work? Hello World is completely useless, non-object-oriented programming, which confirms you have got your program set up correctly. I suggest you follow these steps:-
  • 1: Open new command prompt
  • 2: Give it this instruction (you can use a different folder name): mkdir java
  • 3: cd java (You can use this instruction whenever you open a command line to access your java folder)
  • 4: edit HelloWorld.java (the actual text follows below), then exit and save
  • 5: javac HelloWorld.java
  • 6: java HelloWorld
  • 7: You should get "Hello, World!" as output.
  • Tell us whether you get any errors with that lot.
    Ben Lall
    Greenhorn

    Joined: May 25, 2012
    Posts: 3
    No, it worked fine:

    Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Ben>cd java

    C:\Users\Ben\java>javac HelloWorld.java

    C:\Users\Ben\java>java HelloWorld
    Hello, World!

    C:\Users\Ben\java>
    Darryl Burke
    Bartender

    Joined: May 03, 2008
    Posts: 4642
        
        5

    Ben Lall wrote:Well now, whenever I try to run anything to do with java ...

    You need to TellTheDetails of that. Run what? How?


    luck, db
    There are no new questions, but there may be new answers.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39436
        
      28
    If you can run a HelloWorld program, you should be able to run other programs.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Can't set path