# Exception in thread “LWJGL Application”

I'm using libGDX for my android game in which I'm trying to use bitmap fonts. I have created .fnt and .png bitmap files using Bitmap font generator of angel code.Both .fnt and .png have been placed under same folder /asset/data in my project.

Now when I try to run my project I get exception errors. Here is my sample code -

FileHandle handle = Gdx.files.internal("data/calib.fnt");
FileHandle handle2 = Gdx.files.internal("calib_0.png");
font = new BitmapFont(handle,handle2,true);
font.draw(batchmaker, "abcdef", x,y);


The error on console looks like this (showing only relevant lines):

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: data/calib.fnt . . . at com.badlogic.gdx.graphics.g2d.BitmapFont\$BitmapFontData.(BitmapFont.java:809) Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Invalid font file: data/calib.fnt

I do not believe this error has something to do with issue with paths, because it gives me different errors when I play around by changing the paths.

I have been trying to fix this since almost last 2 days but couldn't come up with a solution. Can someone please let me know what could be the problem or am I missing something?

Edit: Or could there be some checks in which the parameters of calib.fnt is not passing (due to upper/lower case name mismatch with libGDX lib files) ? Please help!

• Check png file containing folder. Try it to put in same folder in which your fnt file is – MGDroid Mar 31 '14 at 6:23

I will show you all the procedure of implementing BitmapFonts in LibGdx :

1. Open it and generate your font (create .fnt and .png files)

2. In LibGdx :

BitmapFont font;

font = new BitmapFont(Gdx.files.internal("fonts/font.fnt"), Gdx.files.internal("fonts/font.png"), false);

font.draw(spriteBatch, str, fX, fY);


You should either not pass the .png file at all in your BitmapFont constructor (since the glyph images for your font are loaded from the font .png provided along with the .fnt file anyway, if you don't indicate some other texture region), or at least indicate the same path in the FileHandle initializing row as in the one for the .fnt file. You said they are both in the same location, so make it to be the same in your code as well (one is "data/calib.fnt" and the other one is "calib_0.png").

The issue was with the bitMap font generator tool I was using. It was BitMap Font generator from angel code. Now I switched to hiero and it works magically.