I'm trying to load a font in libGDX. But I can't figure out want I do wrong.

Code:

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


Error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: fonts/white.font
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:657) at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.<init>(BitmapFont.java:469)
at scenes.GameMode.create(GameMode.java:61)
at scenes.GameMode.<init>(GameMode.java:45)
at com.circle.game.Circle.create(Circle.java:17)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120) Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1931) at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:480)
... 7 more
:desktop:run


• The error says "File not found: font/white.font". Your directory seems to be called "fonts", not "font". – Anko Oct 12 '15 at 18:47
• Ok that was an Error but not the Error. I'm still getting the error :( com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: fonts/white.font – Kevin Oct 12 '15 at 18:57
• That is a very different error. It sounds like the file is now found, but can't be loaded for another reason. Please edit the question accordingly. – Anko Oct 12 '15 at 19:16
• Since you also have a white.png file, that makes me think you want to use the three-argument BitmapFont constructor that takes a font file (specifying glyph positions) as well as an image file (containing the actual glyph images). Could that be it? – Anko Oct 12 '15 at 19:37

With LibGDX, the user.dir property is used for the Gdx.files.internal(...) root directory. This property is, unless explicitly changed, set to the directory from which the app was launched.
Also, after the first step (Whatever it may be, you should use assets/fonts/white.font rather than fonts/white.font, as LibGDX does not automatically use the assets folder.