Solved NullPointer Exception?

Discussion in 'Plugin Development' started by DoggyCode™, Nov 21, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    DoggyCode™

    I'm getting a NullPointer exception in onEnable when I try to

    try (Reader reader = new InputStreamReader(nCore.class.getResourceAsStream(getDataFolder().toString() + File.separatorChar + "testjson" + ".json"), "UTF-8")) {

    nCore is the class extending JavaPlugin, and yes, I have an existing file called "testjson.json" inside plugins/ncore

    Code:
    [19:11:13 ERROR]: Error occurred while enabling nCore v1.0-SNAPSHOT (Is it up to
    date?)
    java.lang.NullPointerException
            at java.io.Reader.<init>(Unknown Source) ~[?:1.8.0_101]
            at java.io.InputStreamReader.<init>(Unknown Source) ~[?:1.8.0_101]
            at me.expdev.ncore.nCore.setup(nCore.java:55) ~[?:?]
            at me.expdev.ncore.nCore.onEnable(nCore.java:27) ~[?:?]
    Line 55 is
    PHP:
    try (Reader reader = new InputStreamReader(nCore.class.getResourceAsStream(getDataFolder().toString() + File.separatorChar "testjson" ".json"), "UTF-8")) {
     
  2. Offline

    Zombie_Striker

    @DoggyCode™
    If the file null? Is the resource stream null?
     
  3. Offline

    jlin13

    @DoggyCode™
    Why are you trying to get the InputStream at runtime? Do you not have another way to access a reference to the stream?
     
  4. Offline

    DoggyCode™

    @Zombie_Striker @jlin13

    Well, instead of using nCore.class.getResourceAsStream(getDataFolder().toString() + File.separatorChar + "testjson" + ".json", I switched to just new File(...) and it worked.
     
Thread Status:
Not open for further replies.

Share This Page