2013年12月19日星期四

Can not find or load main class

I'm furious ! java beginner, engage in the afternoon today , there are two problems:
.
1 compile time , a direct hit in the dos window javac Test.java prompt " File not found" , so I added a path in front : "c: \ Users \ 1 \ desktop \ Test.java " just fine , gave birth to the class file , though passed, but still have a problem , why others can not trails?
After
2. generate class files , enter "java Test" Enter a " Can not find or load main class " in the dos window, I found a lot of solutions will not work.

environment variables:

Classpath:;.% Java_Home% \ lib

Java_Home: D: \ Program Files \ Java \ jdk1.7.0_11

Path:% Java_Home% \ bin

code is as follows :

public class Test

{

public static void main (String [] args)

{

System.out.println ("Hello World!");

}

}
these two problems are not related ah ?
------ Solution ---------------------------------------- ----
your working directory in the desktop cmd in what
------ For reference only ---------------------- -----------------
great God please help me , Online!
------ For reference only -------------------------------------- -
java installed on it?
Open dos:
java-version

take a look at what the output
------ For reference only ----------------------------- ----------
certainly fitted the way, is the 1.6 version , I just found a problem that only in the root directory of each disk in order to compile and run successfully. For example, I built on the D drive a Test.java, dos window and then type D: Enter, then type javac Test.java ( no need to enter the path ) , compiled successfully , enter java Test return, run success. How is this going ?
------ For reference only -------------------------------------- -
Yes, ah , no, , dos default is c: \ users \ 1 below
------ For reference only --------------- ------------------------


your files in c: \ users \ 1 \ desktop you are in c: \ users \ 1 how might find it?

When you hit java Test he will not help you scan your hard disk to find Test.class ah
------ For reference only ---------------- -----------------------


You look at my reply to the third floor , is not only to build java files in the root directory ah
------ For reference only ---------------- -----------------------


not

Because you do when your working directory is D: \ where your files are

If you want to place the file in c: \ users \ 1 \ desktop, when you first thing to do is punch cmd
cd desktop

then javac Test.java
java Test
------ For reference only ------------------------------- --------
that if I usually put the program files on the E drive a folder under the n how do
------ For reference only ------ ---------------------------------


For example, the file in your E: \ toto \ titi \ Test.java

either after you hit cmd
e:
cd toto \ titi
javac Test.java
java Test After you hit cmd either

javac E: \ toto \ titi \ Test.java
java E: \ toto \ titi \ Test
------ For reference only ------------------------ ---------------
  The reply was deleted administrator at 2013-01-18 08:58:02

------ For reference only ---------------------------------- -----
Thank you very much !
------ For reference only -------------------------------------- -
this run java program also appeared "Unable to load the main class " error , close the DOS window , then enter the program directory , run no such mistake , very strange , oh !
------ For reference only -------------------------------------- -
I know why
Right-click the project properties-java Builder Path-Libraries see your jdk right

没有评论:

发表评论