Program Randomly Quitting After Font.createFont() statement

After I try to get the font "ggsans", which is in the src/main/resources folder, the program randomly quits with exit code 1. Code
static {
try {
System.out.println("Test Statement!");
ggReg = Font.createFont(Font.TRUETYPE_FONT, new File("ggsans.ttf"));
ggBold = Font.createFont(Font.TRUETYPE_FONT, new File("ggsansbold.ttf"));
} catch (FontFormatException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static void main(String[] args) {
System.out.println("Test Statement!");
frame = new JFrame();
System.out.println("Test Statement!");
frame.add(new MainPanel());
System.out.println("Test Statement!");
frame.setVisible(true);
System.out.println("Test Statement!");
}
static {
try {
System.out.println("Test Statement!");
ggReg = Font.createFont(Font.TRUETYPE_FONT, new File("ggsans.ttf"));
ggBold = Font.createFont(Font.TRUETYPE_FONT, new File("ggsansbold.ttf"));
} catch (FontFormatException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static void main(String[] args) {
System.out.println("Test Statement!");
frame = new JFrame();
System.out.println("Test Statement!");
frame.add(new MainPanel());
System.out.println("Test Statement!");
frame.setVisible(true);
System.out.println("Test Statement!");
}
7 Replies
JavaBot
JavaBotโ€ข2mo ago
โŒ› This post has been reserved for your question.
Hey @๐“ฑ๐“ฒ๐“ถ ๐“ซ๐“พ๐“ฝ ๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
๐“ฑ๐“ฒ๐“ถ ๐“ซ๐“พ๐“ฝ ๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚
It outputs just one "Test Statement" and then exits One thing to note is that there's a lil pause in between the first test statement and the quit. Output
Test Statement!
[pause]
Process finished with exit code 1
Test Statement!
[pause]
Process finished with exit code 1
JavaBot
JavaBotโ€ข2mo ago
๐Ÿ’ค Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Mandagus ล ernas
Mandagus ล ernasโ€ข2mo ago
new File("ggsans.ttf")
File operates with file system. For loading from classpath (which is what src/main/resources belongs to) you have to use something else, eg , https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html#getResourceAsStream(java.lang.String)
frame = new JFrame();
you shouldn't be interacting with swing component classes outside of swing thread. Use https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable)
SwingUtilities (Java SE 17 & JDK 17)
declaration: module: java.desktop, package: javax.swing, class: SwingUtilities
Class (Java SE 17 & JDK 17)
declaration: module: java.base, package: java.lang, class: Class
JavaBot
JavaBotโ€ข2mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBotโ€ข2mo ago
Post Closed
This post has been closed by <@663052037688131614>.

Did you find this page helpful?