Reading resource file issue

Hi. I was making a language system for my project and it threw a NullPointerException. Every solution on the internet did not work. For some reason, the code that reads the image on the same resources folder did work. So, heres the code:
private String getLocalizedJson() throws IOException {
return new String(getClass().getClassLoader().getResourceAsStream("/resources/localizedtexts.json").readAllBytes());
}
private String getLocalizedJson() throws IOException {
return new String(getClass().getClassLoader().getResourceAsStream("/resources/localizedtexts.json").readAllBytes());
}
Stack trace:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.InputStream.readAllBytes()" because the return value of "java.lang.ClassLoader.getResourceAsStream(String)" is null
at com.mokkachocolata.util.Localization.getLocalizedJson(Localization.java:25)
at com.mokkachocolata.util.Localization.getLocalizedText(Localization.java:50)
at com.mokkachocolata.project.adbgui.MainFrame.init(MainFrame.java:56)
at com.mokkachocolata.project.adbgui.App.main(App.java:45)
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.InputStream.readAllBytes()" because the return value of "java.lang.ClassLoader.getResourceAsStream(String)" is null
at com.mokkachocolata.util.Localization.getLocalizedJson(Localization.java:25)
at com.mokkachocolata.util.Localization.getLocalizedText(Localization.java:50)
at com.mokkachocolata.project.adbgui.MainFrame.init(MainFrame.java:56)
at com.mokkachocolata.project.adbgui.App.main(App.java:45)
21 Replies
JavaBot
JavaBot9mo ago
This post has been reserved for your question.
Hey @Mokka Chocolata! 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 closed 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.
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Mokka Chocolata
Mokka ChocolataOP9mo ago
yeah but its actually there
No description
Mokka Chocolata
Mokka ChocolataOP9mo ago
its a weird problem also log4j doesnt read it
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Mokka Chocolata
Mokka ChocolataOP9mo ago
okay
Mokka Chocolata
Mokka ChocolataOP9mo ago
No description
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Mokka Chocolata
Mokka ChocolataOP9mo ago
the localization class just ignore that im not using the java locale class
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Mokka Chocolata
Mokka ChocolataOP9mo ago
umm i dont know but the app icon displays correctly though like
setIconImage(Toolkit.getDefaultToolkit().
getImage(this.getClass().getResource("/resources/appicon.png")));
setIconImage(Toolkit.getDefaultToolkit().
getImage(this.getClass().getResource("/resources/appicon.png")));
and it works just fine
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Mokka Chocolata
Mokka ChocolataOP9mo ago
nope
Mokka Chocolata
Mokka ChocolataOP9mo ago
marked it
No description
Mokka Chocolata
Mokka ChocolataOP9mo ago
it does not work it remains the same resource not found removing the first slash? nope just the file?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Mokka Chocolata
Mokka ChocolataOP9mo ago
like without the slash it works but yeah there is a next problem that i can solve
JavaBot
JavaBot9mo 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.
Mokka Chocolata
Mokka ChocolataOP9mo ago
so yeah done
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot9mo ago
Post Closed
This post has been closed by <@792625376987054100>.
Want results from more Discord servers?
Add your server