Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java 8 with LibGDX

I'm writing a game in Java using LibGDX, with only desktop as the targeted platform. I just created a new LibGDX project, and imported some existing code into it, but now I'm getting a few errors. Specifically, using the diamond operator. For example, this line of code:

HashMap<String, Integer> connectionsMap = new HashMap<>();

is generating this error:

Error:(20, 37) java: diamond operator is not supported in -source 1.6
(use -source 7 or higher to enable diamond operator)

Ideally, I'd like to use Java 8. The Gradle files in the module I imported were preserved, so I changed the sourceCompatibility line in all the other build.gradle files throughout the project from 1.6 to 1.8, and I made sure that in the Project Structure > Project > Language Level was set to Java 8. However, I'm still getting this issue. What else do I need to change for my project to use Java 8?

like image 816
Thomas Avatar asked May 01 '17 15:05

Thomas


People also ask

Does libGDX use Java?

libGDX is a cross-platform Java game development framework based on OpenGL (ES) that works on Windows, Linux, macOS, Android, your browser and iOS.

How do I update libGDX?

Eclipse: Select all your projects in the package explorer, right click, then click Gradle -> Refresh All . This will download the libGDX version you specified in build. gradle and wire up the JAR files with your projects correctly.


1 Answers

If you're using IntelliJIDEA, make changes in three places.

  1. sourceCompatibility = 1.8 in build.gradle file of all modules

  2. Project Structure > Project > Language Level

  3. Project Structure > Modules > Sources Tab on all modules > Language Level

like image 129
Abhishek Aryan Avatar answered Nov 05 '22 06:11

Abhishek Aryan