Reputation: 107
I've been developing a 2D game (using LibGDX) and I've been getting crashes on SOME devices during my Alpha test. From the pre-launch report, the issue is as follows:
java.lang.NullPointerException: Attempt to invoke interface method 'void com.badlogic.gdx.audio.Music.setLooping(boolean)' on a null object reference
at com.bonbon.lubyjump.game.Game.initialiseSounds(Game.java:151)
at com.bonbon.lubyjump.game.Game.loadSounds(Game.java:147)
at com.bonbon.lubyjump.game.Game.create(Game.java:102)
atcom.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:311)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
From what I understand, setLooping()
would throw the above error only if there was no "Theme.wav" audio file. But the fact that some devices are running without any crashes seems to indicate that the audio file DOES exist. Is there anything I might've overlooked that could be generating the NullPointerException
? I haven't been able to recreate the error on any virtual devices in Android Studio.
private void loadSounds() {
try {
themeSong = Gdx.audio.newMusic(Gdx.files.internal("Theme.wav"));
gamePlaySong = Gdx.audio.newMusic(Gdx.files.internal("Gameplay.wav"));
jumpSound = Gdx.audio.newSound(Gdx.files.internal("Jump.wav"));
fartSound = Gdx.audio.newSound(Gdx.files.internal("Fart.wav"));
gameOverSound = Gdx.audio.newSound(Gdx.files.internal("GameOver.wav"));
} catch (Exception e) {
e.printStackTrace();
}
initialiseSounds();
}
private void initialiseSounds(){
themeSong.setLooping(true); //This line causes the error
themeSong.setVolume(soundVolume);
themeSong.play();
gamePlaySong.setVolume(soundVolume);
}
Upvotes: 1
Views: 150
Reputation: 107
To anyone who may have encountered the same problem, I found out that certain devices were crashing because they could not process wav files, which was the format I used for my audio files. Once I converted them to mp3, the issue was resolved and all devices ran without crashing.
Upvotes: 0