Programing

새 LibGDX 프로젝트를 실행할 때“파일을 찾을 수 없습니다”

lottogame 2020. 7. 22. 21:49
반응형

새 LibGDX 프로젝트를 실행할 때“파일을 찾을 수 없습니다”


LibGDX를 배우려고 노력하면서 여기나열된 모든 소프트웨어를 새로운 형식의 Mac OS X Maverick에 새 Eclipse 4.3과 함께 설치합니다 .

재부팅 후 모든 것이 순조롭게 진행됩니다. gdx-setup.jar를 다운로드하여 실행하고 양식을 채우고 Eclipse로 가져옵니다.

데스크탑을 실행하려고 할 때 오류, 경고가 없습니다. (데스크톱 프로젝트 인 Run As-> Java Application을 마우스 오른쪽 단추로 클릭하십시오).

이 오류가 발생했습니다

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: badlogic.jpg
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
at com.diesel.bugs.DieselBugs.create(DieselBugs.java:21)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)


Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: badlogic.jpg (Local)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:134)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:218)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)

나는 비슷한 문제를 많이 발견했는데 좋은 결과없이 모든 것을 시도했습니다 ... 어제 밤에 이것을 발견 했습니다 . 매우 시원합니다. 최신 Java 1.8, mac 및 Eclipse가 완벽하게 맞습니다 ...

그러나 성공하지 못했습니다 .Java 1.6 및 1.7을 사용해보십시오. 항상 동일한 오류 (파일을 찾을 수 없으며 Java 1.7을 유지했습니다)

가져 오기에 의해 생성 된 원래 코드의 유일한 수정은 디버그를 시작합니다.

package com.diesel.bugs;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class DieselBugs extends ApplicationAdapter {
    SpriteBatch batch;
    Texture imgExternal,imgLocal;

    @Override
    public void create () {
        batch = new SpriteBatch();
        String pathLocal = Gdx.files.getLocalStoragePath();
        String pathExternal = Gdx.files.getExternalStoragePath();
        Boolean isExternal = Gdx.files.isExternalStorageAvailable();
        Boolean isLocal = Gdx.files.isLocalStorageAvailable();
        imgExternal = new Texture(Gdx.files.external("/Desktop/badlogic.jpg"));
        imgLocal = new Texture(Gdx.files.local("badlogic.jpg")); 
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(imgExternal, 0, 0);
        batch.end();
    }
}

이상한 점은 pathLocal이 ""와 같습니다. Gdx.files.getLocalStoragePath ()가 아무것도 반환하지 않는 것이 정상입니까 (빈 문자열)?

또한

imgExternal = new Texture(Gdx.files.external("/Desktop/badlogic.jpg"));

잘 작동합니다. 로컬 로컬 만 오류를 제공하고 isLocal 및 isExternal이 true를 리턴합니다.

그리고 조합 등의 많은 시도 /assets/data/badlogic.jpg, /assets/badlogic.jpg, /data/badlogic.jpg, data/badlogic.jpg,와 badlogic.jpg.

이미지 badlogic.jpg가 있으며 확실하게 여러 위치에 넣었습니다.

그리고 지금 내가 도움을 받기 위해 온 이유는 PC에서 동일한 단계를 모두 시도하고 모든 것이 잘 작동하기 때문입니다.

새 Mac에 어떤 문제가 있으며 설정이 되셨습니까?


libgdx 위키에서

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.


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.

참고URL : https://stackoverflow.com/questions/22822767/file-not-found-when-running-new-libgdx-project

반응형