Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"File not found" when running new LibGDX project

Tags:

java

libgdx

From libgdx wiki

When you run Desktop Project

The application will fail the first time. Open the Run Configuration you just created and set the working directory to the android/assets/ directory!

link your desktop project to android assets folder?

Go to Run => Run Configurations.. => choose DesktopLauncher, Arguments Tab => Working Directory => Others then browse to yourproject-android/assets/ and click Apply => Run

enter image description here


For those of us using Android Studio or IntelliJ IDEA, you need to follow these steps:

  1. Select Run -> Edit Configurations from the menu

  2. In the "Working Directory:" text box, append "/android/assets" to the path.

Note that if you execute tasks with gradle, this is not an issue. The gradle.build files are configured to use the assets folder from the android module.


Note that the previous answers will not work for users who unchecked the "Android" box on setup. There should really be a default assets folder installed for those who don't care about deploying for Android.


For those using Intellij IDEA:

  1. Run -> Edit Configurations
  2. On the left hand side choose: Application -> DesktopLauncher
  3. In the "Configuration"-Tab, undert "Working directory" choose your android/assets path

This is how you fix it properly without playing around with the working directory:

The problem is that the asset folder is not correctly marked as resources directory for the gradle build. To fix this you have to add the following line in the ./core/build.gradle build file:

sourceSets.main.resources.srcDirs = [ "assets/" ]

My file after a clean setup with the recent libGDX version looks like this:

apply plugin: "java"

sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = [ "assets/" ]

eclipse.project {
    name = appName + "-core"
}

I use a different solution.

Instead of creating an application run configuration, create a Gradle build configuration. The task is desktop:run. Once it is executed, the game (should) launch and stay alive without crashing, and the resources should be found.

I am not exactly sure why, but when a Gradle task is run like this, the resources are found. When an application run configuration is used (without modifications like the currently accepted answer) it crashes because it can't find the resources.