mercredi 7 mai 2014

Windows - classe introuvable dans Java - Stack Overflow


I just wrote a Java file, "Inizio.java". When compiling it using the command javac, everything's alright, the file is found and the command prompt doesn't write anything back in return (it should be normal, isn't it?). When trying to execute the file, writing "java Inizio", the command prompt tells me that "it can't find or load the principal class Inizio". It seems the classpath and path variables are installed correctly; in fact, when I write "set CLASSPATH" or "set Path" in the command prompt, it writes back the value I gave them. Just to clarify, I use Windows 7 (I tried to use Java on Linux Ubuntu with no results - I couldn't set the Path or Classpath variables...) I don't know where's the problem... Could you help me please?


Here's the code I wrote in the file (the text format here isn't excellent):


class Inizio{
public static void main(String[] args){
System.out.println("Today");
}
}



If your file is called Inizio.java, it needs to declare a public class of the same name. Assuming you have no package declarations, change the content of your file to:


public class Inizio {
public static void main(String[] args){
System.out.println("Today");
}
}

Compile and run as usual:


javac Inizio.java
java Inizio

This should work.



I just wrote a Java file, "Inizio.java". When compiling it using the command javac, everything's alright, the file is found and the command prompt doesn't write anything back in return (it should be normal, isn't it?). When trying to execute the file, writing "java Inizio", the command prompt tells me that "it can't find or load the principal class Inizio". It seems the classpath and path variables are installed correctly; in fact, when I write "set CLASSPATH" or "set Path" in the command prompt, it writes back the value I gave them. Just to clarify, I use Windows 7 (I tried to use Java on Linux Ubuntu with no results - I couldn't set the Path or Classpath variables...) I don't know where's the problem... Could you help me please?


Here's the code I wrote in the file (the text format here isn't excellent):


class Inizio{
public static void main(String[] args){
System.out.println("Today");
}
}


If your file is called Inizio.java, it needs to declare a public class of the same name. Assuming you have no package declarations, change the content of your file to:


public class Inizio {
public static void main(String[] args){
System.out.println("Today");
}
}

Compile and run as usual:


javac Inizio.java
java Inizio

This should work.


Related Posts:

0 commentaires:

Enregistrer un commentaire