i am currently trying to run a java file in the terminal inside the corresponding package, which i created in eclipse (so its not the default package). However, the problem began after i tried to compile my file with:
javac Übung13.java
This just produced the following output:
▄bung13.java:2: error: illegal character: '\u00bc'
package ├╝bung1;
Shortly, i found out, that the cause was the || character, which is equivalent to the "or"-operator in boolean algebra. I then tried :
javac -encoding UTF8 Übung13.java
There was no output, therefore i thought, that it compiled whithout any problems, and there was also an Übung13.class file inside the package, which also emphasized that i was right. But when i try to execute my java file, then it prints the following output:
java Übung13
Fehler: Hauptklasse Übung13 konnte nicht gefunden oder geladen werden
Ursache: java.lang.NoClassDefFoundError: übung1/Übung13 (wrong name: Übung13)
This implies that my package contains no class, but this cant be true, since i compiled the file successfully. This is the point where i also cant find any solutions. Help would be appreciated greatly.
Here is the source code of my java file in case that there are any mistakes, but the file ran without any errors in the eclipese IDE, so i highly doubt that.
// -*- coding: utf-8 -*-
package übung1;
public class Übung13 {
public static void main(String[] args) {
if (args.length > 0) {
System.out.println("Das erste Kommandozeilenargument ist: " + args[0]);
} else {
System.out.println("Keine Kommandozeilenargumente vorhanden.");
}
/*
* args ist eine variable welche für das Terminal steht bzw. man kann sie als array betrachten
* welcher als index die zeilen angibt.
*/
System.out.println(args.length);
//Beispiel für eine Interaktion mit dem Terminal um die Summe zweier zahlen zu errechnen
try {
if (args.length == 0 || args.length == 1) {
}
} catch (NumberFormatException e) {
System.out.print("Falsche Eingabe");
};
}
}
Also my path to the java file:
eclipse-workspace\Übungen\src\übung1
1.
javac Übung13.java
javac -encoding UTF8 Übung13.java
java übung1.Übung13
java Übung13.java
\u00bcis the unicode character for¼also your error message is complaining about theÜin classname. Its hard to get a piccture of this but you can change the name of your compiled jar to.zipand extract its contents to look at what the directory structure looks like inside the jar-file. But its very hard to help since you have not supplied any simple instructions how to reproduce.java -XshowSettings:all 2>&1 | findstr "encoding"übung1- so it must be executed asjava übung1.Übung13but from the folder that containsübung1, that is, fromeclipse-workspace\Übungen\srcassuming thatÜbung13.classwas created ineclipse-workspace\Übungen\src\übung1(oreclipse-workspace\Übungen\srcmust be added to the CLASSPATH: java -cp eclipse-workspace\Übungen\src übung1.Übung13`) -- anyway strongly discouraged to use Umlaute (or similar) in package or class names - but note that eclipse usually is configured to use a different folder for generated .class files