[英]Libgdx on android not able to detect GDX fonts
I am trying to render simple text using the libgdx BitmapFont
: 我试图使用libgdx
BitmapFont
渲染简单的文本:
font = new BitmapFont();
font.draw(batch, "Tap anywhere to begin!", 100, 100);
It works fine in the desktop,But android it gives this error: 它在桌面上工作正常,但android它给出了这个错误:
07-30 08:12:35.518: ERROR/AndroidRuntime(817): FATAL EXCEPTION: GLThread 82
com.badlogic.gdx.utils.GdxRuntimeException: File not found: com/badlogic/gdx/utils/arial-15.fnt (Classpath)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:132)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.<init>(BitmapFont.java:715)
at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:114)
at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:73)
at com.mangokidzee.amphibian.Activity1.create(Activity1.java:23)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:322)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Seems it is unable to load the font file 似乎无法加载字体文件
File not found: com/badlogic/gdx/utils/arial-15.fnt (Classpath)
I am using intelliJ Idea
not the Eclipse IDE. 我使用的是
intelliJ Idea
而不是Eclipse IDE。 I think this is due to some path configuration issue but not able to figure out what. 我认为这是由于一些路径配置问题,但无法弄清楚是什么。 Can someone help me out?
有人可以帮我吗?
Update 更新
I have opened sample libgdx demo apk created using eclipse
, it has these 4 files in the gdx utils
folder 我已经打开了使用
eclipse
创建的示例libgdx demo apk,它在gdx utils
文件夹中有这4个文件
whereas in my apk generated using intelliJ
, it has only 2 files 而在我使用
intelliJ
生成的apk中,它只有2个文件
arial-15
is missing. 缺少
arial-15
。
After I removed the gdx-sources.jar from main lib dir,every thing works fine. 从主lib目录中删除gdx-sources.jar之后,一切正常。 Maybe a bug of IntelliJ IDEA?
也许是IntelliJ IDEA的错误?
removing the gdx-sources.jar
from main libs
dir, works fine but we need the documentation when we press Ctrl+Q when using IntelliJ. 从主
libs
dir中删除gdx-sources.jar
,工作正常但我们在使用IntelliJ时按Ctrl + Q时需要文档。
So, I didn't delete the gdx-sources.jar
but I MOVED it in a new directory under Main
, named it sourcelibs
and then I went to project structure/Libraries/Mainlibs
(or whatever) and at the dependencies I deleted the sources entry (it had no meaning any more) and pressed the "plus sign" to attach files or directories and I added the new directory. 所以,我没有删除
gdx-sources.jar
,但我把它下一个新的目录Main
,将其命名为sourcelibs
,然后我去project structure/Libraries/Mainlibs
(或其他),并在依赖我删除源条目(它没有任何意义)并按下“加号”来附加文件或目录,我添加了新目录。 Now there is a new sources entry with the new directory. 现在,新目录中有一个新的源条目。
So now there is no error (thanks to user2206917), and we also have the documentation! 所以现在没有错误(感谢user2206917),我们也有文档!
I got this error because of a problem with the desktop run configuration. 由于桌面运行配置存在问题,我收到此错误。 As noted on the libgdx docs (Alternative 2: Working directory) the working directory of the build configuration should be set to the android/assets folder.
如libgdx文档 (备选方案2:工作目录)所述,构建配置的工作目录应设置为android / assets文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.