0

So, I was able to run a Java program within Eclipse. While in Eclipse, the NullPointerException does NOT show within the terminal, however when trying to execute the Clip as an executable Jar within GitBash, I get the following stack trace.

If it's a NullPointerException, the variable/method is pointing to something null, but how can that be null while the program is a Jar file, and it isn't Null while in Eclipse. Why is that the case that it is compiling within Eclipse?

    $ javaw.exe -jar CookieClicker.jar
    Exception in thread "main" java.lang.NullPointerException: Cannot invoke 
    "javax.sound.sampled.Clip.setFramePosition(int)" because "this.clip" is null
        at com.tbonegames.SoundFX.play(SoundFX.java:51)
        at com.tbonegames.SoundFX.playSoundEffect(SoundFX.java:29)
        at com.tbonegames.CookieMain.<init>(CookieMain.java:73)
        at com.tbonegames.CookieMain.main(CookieMain.java:68)
E_net4
  • 27,810
  • 13
  • 101
  • 139
  • 2
    Eclipse "Run Configuration" settings will be using the Eclipse build with current working directory for the project. That isn't necessarily the same as what is in your jar and the current working directory for the command line. Double check them and consider what is relying on current working directory of the project. – DuncG Aug 31 '22 at 16:39
  • 2
    A common problem is that you are trying to read something from the Jar using a File based API. Objects in a Jar are not files and you can't read them like that. You need to show us your code. – greg-449 Aug 31 '22 at 16:40
  • 1
    I agree with the O/P. This question is different than the usual questions about NPE, and general response about NPEs isn't helpful in this case. – Old Dog Programmer Aug 31 '22 at 17:00

0 Answers0