问题描述
现在,我正在用 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 的版本有关.我尝试再次运行设置 UI,我尝试了其他版本的 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.
这是完整的堆栈跟踪:
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!
对名称为向 BitmapFont 添加多页字体;正在更新 FreeTypeFontGenerator..."的 libgdx 的提交添加了对 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 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!