ввод из командной строки в java

Попытка обеспечить ввод с помощью команды в Java-программе. Вот код.

public class Hola {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(args[0]);
        System.out.println(args[0]);
        System.out.println(args[0]);
        System.out.println(args[0]);
    }
}

Но при попытке запустить его из командной строки выдает ошибку. Я использую Ubuntu 18.04. Вот ошибка:

Ошибка: произошла ошибка LinkageError при загрузке основного класса Hola java.lang.UnsupportedClassVersionError: Hola была скомпилирована более поздней версией Java Runtime (версия файла класса 58.0), эта версия Java Runtime распознает только версии файла класса до 55.0

1
задан 8 July 2020 в 10:12

1 ответ

The error means that you compiled your Java program with a version of the compiler that is more recent than the version of the Java virtual machine you're trying to execute the compiled code.

In your case 58 means Java 14 and 55 means Java 11. Thus, you compiled your program with Java 14 and you're trying to execute the compiled code with Java 11.

Probably your configuration of the Java virtual machine is not in sync with your configuration of your Java compiler.

Maybe you ran something like sudo update-alternatives --config java (JVM) but not sudo update-alternatives --config javac (Java compiler).

To avoid such problems, in Ubuntu, you can run sudo update-java-alternatives, which takes care of setting the version both for java and for javac.

3
ответ дан 30 July 2020 в 22:12

Другие вопросы по тегам:

Похожие вопросы: