Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error on token "-", -- expected

I am using Eclipse IDE for Java Developers, Kepler Service Release 2, with jdk1.8.0 installed as the JRE.

I am using Java All-in-one For Dummies to learn Java SE 8, and, when writing a program, using Swing, I am getting this error: syntax error on token "-", -- expected

With this code:

button1 = new JButton("Click me!");
button1.addActionListener(e -> button1Click() );
panel1.add(button1);

exitButton = new JButton("Exit");
exitButton.addActionListener(e -> exitButtonClick() );
panel1.add(exitButton);
this.add(panel1);

button1 and exitButton have been declared as JButtons already, and I have imported javax.swing.* and java.awt.event.*.

How can I fix this?

like image 840
A_Bush Avatar asked Dec 04 '22 06:12

A_Bush


1 Answers

if you are on kepler install this update : http://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler

and then set

windows > preferences > java > compiler > compiler compliance level > 1.8 
like image 101
jmj Avatar answered Feb 03 '23 03:02

jmj