Defective
Defective
JCHJava Community | Help. Code. Learn.
Created by Defective on 7/17/2024 in #java-help
Trying to load a Font from resources throws a BufferUnderflowException
I am trying to load a Selawik font from my project's resources with following code:
try (InputStream is = getClass().getResourceAsStream("/fonts/selawk.ttf")) {
Font selawik = Font.createFont(Font.TRUETYPE_FONT, is);
}
try (InputStream is = getClass().getResourceAsStream("/fonts/selawk.ttf")) {
Font selawik = Font.createFont(Font.TRUETYPE_FONT, is);
}
but it results in an exception:
java.awt.FontFormatException: java.nio.BufferUnderflowException
at java.desktop/sun.font.TrueTypeFont.init(TrueTypeFont.java:532)
at java.desktop/sun.font.TrueTypeFont.<init>(TrueTypeFont.java:216)
at java.desktop/sun.font.TrueTypeFont.<init>(TrueTypeFont.java:196)
at java.desktop/sun.font.SunFontManager.createFont2D(SunFontManager.java:2208)
at java.desktop/java.awt.Font.createFont0(Font.java:1169)
at java.desktop/java.awt.Font.createFont(Font.java:1076)
at io.github.defective4.onematch.game.Application.<init>(Application.java:82)
at io.github.defective4.onematch.game.Application.<clinit>(Application.java:69)
java.awt.FontFormatException: java.nio.BufferUnderflowException
at java.desktop/sun.font.TrueTypeFont.init(TrueTypeFont.java:532)
at java.desktop/sun.font.TrueTypeFont.<init>(TrueTypeFont.java:216)
at java.desktop/sun.font.TrueTypeFont.<init>(TrueTypeFont.java:196)
at java.desktop/sun.font.SunFontManager.createFont2D(SunFontManager.java:2208)
at java.desktop/java.awt.Font.createFont0(Font.java:1169)
at java.desktop/java.awt.Font.createFont(Font.java:1076)
at io.github.defective4.onematch.game.Application.<init>(Application.java:82)
at io.github.defective4.onematch.game.Application.<clinit>(Application.java:69)
Does anyone have any clue why? The font appears to be a valid TrueType font, but Java still refuses to load it...
7 replies
JCHJava Community | Help. Code. Learn.
Created by Defective on 12/27/2023 in #java-help
Database Connection Pooling
I need to implement a simple connection pooling mechanism for my application. The problem is I have almost no knowledge working with database connections. What things should I take into account? Is there any lightweight library out there? I expect the code to open as few connections as possible.
20 replies