LibGDX FreeTypeFontGenerator NoSuchField异常 [英] LibGDX FreeTypeFontGenerator NoSuchField exception

查看:127
本文介绍了LibGDX FreeTypeFontGenerator NoSuchField异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在使用Java中的LibGDX构建一个小游戏,我想使用TTF字体。我已将gdx-freetype.jar和gdx-freetype-natives.jar添加到我的构建路径中,但是当我运行我的应用程序时,出现java.lang.NoSuchFieldError:id错误。负责的代码:

Right now, I'm building a small game with LibGDX in Java, and I want to use a TTF font. I've added gdx-freetype.jar and gdx-freetype-natives.jar to my build paths, but when I get to running my application, I get a "java.lang.NoSuchFieldError: id" error. The code responsible:

FreeTypeFontGenerator generator = new 
FreeTypeFontGenerator(Gdx.files.internal("data/Prosto.ttf"));
BitmapFont font = generator.generateFont(12);
generator.dispose();

我在某处看到它可能与JAR的版本有关。我已经尝试再次运行设置界面,我尝试过其他版本的JAR,但无济于事。

I read somewhere it might have something to do with the versions of the JARs. I've tried running the setup UI again, I've tried JARs from another version, but to no avail.

编辑:这是完整的堆栈跟踪:

Here's the complete stacktrace:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException:    java.lang.NoSuchFieldError: id
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:116)
Caused by: java.lang.NoSuchFieldError: id
at          com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateData(FreeTypeFontGenerator.java:288)
at    com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateFont(FreeTypeFontGenerator.java:137)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.generateFont(FreeTypeFontGenerator.java:148)
at com.serialbit.personal.MainMenu.create(MainMenu.java:44)
at com.serialbit.personal.MainMenu.<init>(MainMenu.java:32)
at com.serialbit.personal.Tyredus.create(TyredusGame.java:8)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:130)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)


推荐答案

今天面临类似的问题 - 你正在使用新版本的freetype扩展而没有更新libgdx!

Faced similar problem today - you are using new version of freetype extension without updating the libgdx!

提交libgdx,名称为将多页字体添加到BitmapFont;更新FreeTypeFontGenerator ...在FreeTypeFontGenerator中添加了Glyph.id字段的使用。

The commit to libgdx with name "Adding multi-page fonts to BitmapFont; updating FreeTypeFontGenerator..." added usage of Glyph.id field in FreeTypeFontGenerator.

Glyph类在libgdx的BitmapFont中。所以不更新libgdx - 它会产生这个异常。

Glyph class is inside BitmapFont of libgdx. So without updating libgdx - it produces this exception.

您还应该更新libgdx - 这将解决此问题。或者使用旧版本的freetype扩展名!

You should update libgdx also - this will solve this issue. Or use older version of freetype extension!

这篇关于LibGDX FreeTypeFontGenerator NoSuchField异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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