1

I'm following a Java's Swing course and I'm trying a simple application.

package gui_01;

import java.awt.EventQueue;
    import javax.swing.JFrame;

    public class SimpleEx extends JFrame{

    public SimpleEx( ) {
        initUI();
    }

    private void initUI() {
        setTitle("Simple example");
        setSize(300, 200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {

        EventQueue.invokeLater(() -> {
            var ex = new SimpleEx();
            ex.setVisible(true);
        });
    }
}

but I get this error when trying to run the application:

Exception in thread "main" java.lang.UnsupportedClassVersionError: gui_01/SimpleEx has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0

I have the following configurations for the project:

JAVA Building PATH config

JAVA Compiler settings

And if I run the command java -version from the terminal I get the following result: Java version got from the Terminal command Java -version

What can I do to solve it? I'm using :

  • Mac: High Sierra
  • Eclipse: 2018-09 (4.9.0)
Cœur
  • 37,241
  • 25
  • 195
  • 267
theme
  • 1,097
  • 2
  • 9
  • 13
  • 1
    The entry for your program in the 'Run > Run Configuration' dialog configures what is used when you run your code. – greg-449 Dec 16 '18 at 10:27
  • Can you show us the Java runtimes on Eclipse? –  Dec 16 '18 at 11:34
  • @greg-449 you were right. In the 'Run > Run Configurations ' I managed to chose the right JRE version and now it works like a charm. Thanks both ;) How to I set this to closed? – theme Dec 16 '18 at 17:41

1 Answers1

0

As @greg-449 suggested going to 'Run > Run Configurations' dialog I managed to select the proper JRE version I want to use. I post some images just in case the solution helps others.

Lots of thanks ;)

Run->Run Configurations Dialog

Go to TAB JRE and there you can select the Running Environment

theme
  • 1,097
  • 2
  • 9
  • 13