“File not found” when running new LibGDX project

£可爱£侵袭症+ 提交于 2019-11-26 15:55:01

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

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.

I haven't Android project. My solution is to add the asset folder to the Java Build Path->Libraries as a Class Folder. Additionally check the asset folder in Java Build Path->Order and Export to include this in other projects.

You can check the path of Assets in working Directory or linked resources .After done check for the file which you are loading .At last clean and refresh the project and enjoy.

I had the same problem in IntelliJ, and I had not generated the libgdx project for Android (Android option was not marked as checked) and I was yet getting the same error. Instead of linking the working directory to "/android/assets/", linked it to "/core/assets" and it worked fine for me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!