“未找到文件”在运行新的LibGDX项目时 [英] "File not found" when running new LibGDX project

查看:153
本文介绍了“未找到文件”在运行新的LibGDX项目时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图学习LibGDX,我安装了列出的所有软件这里在新格式化的Mac OS X Maverick上使用新的Eclipse 4.3。

I trying to learn LibGDX, I install all the software listed here with a new Eclipse 4.3 on a fresh formatted mac OS X Maverick.

一切顺利,重启后,我下载并执行gdx-setup.jar,填写表格,然后导入Eclipse。

Everything goes smooth, after a reboot, I download, and execute the gdx-setup.jar, fill the form, and import into Eclipse.

没有错误,没有警告,当我尝试运行桌面时。 (右键单击桌面项目,Run As - > Java Application)。

No error, no warning, when I try to run the desktop. (Right click the desktop project, 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非常适合......

I found a lot of similar issue here, I try them all without any good result... Last night I found this, very cool I have the latest Java 1.8, a mac, and Eclipse fit perfectly...

但是没有成功,我尝试使用Java 1.6和1.7,总是出现同样的错误(找不到文件,我保留了Java 1.7)

But no success, I try with Java 1.6 and 1.7, Always the same error (No file found, I kept Java 1.7)

我开始做一些调试,这里是我对输入生成的原始代码的唯一修改。

I begin to do some debug, here my only modification of the original code generated by the importation.

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()返回任何内容(空字符串)是否正常?

The weird thing is pathLocal is equal to "". Is it normal for Gdx.files.getLocalStoragePath() to return nothing (empty string)?

此外

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

效果很好。只有本地的一个给出错误,也是isLocal,isExternal返回true。

Works great. only the local one gives the error, also isLocal, and isExternal return true.

我尝试了很多组合,比如 / assets / data /badlogic.jpg /assets/badlogic.jpg /data/badlogic.jpg data / badlogic.jpg badlogic.jpg

And I try a lots of combinations, like /assets/data/badlogic.jpg, /assets/badlogic.jpg, /data/badlogic.jpg, data/badlogic.jpg, and badlogic.jpg.

图片badlogic.jpg在那里,我把它放在多个地方以确定。

The image badlogic.jpg is there and I put it in multiple places to be sure.

现在我在这里求助的原因是我只需在PC上尝试所有相同的步骤,一切都很好。

And now the reason why I'm here for help is I just try all the same step on a PC and everything works great.

我的新Mac及其设置有什么问题?

What is wrong with my new mac and it's setting?

推荐答案

来自libgdx wiki

From libgdx wiki

运行桌面项目时


应用程序第一次失败。打开刚刚创建的运行配置并将工作目录设置为android / assets /目录!

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

将您的桌面项目链接到android资产夹?

link your desktop project to android assets folder?

转到运行 => 运行配置.. =>选择 DesktopLauncher ,参数选项卡=>工作目录=>其他然后浏览到您的项目-android / assets /并单击应用 => 运行

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

这篇关于“未找到文件”在运行新的LibGDX项目时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆