The "How to solve a nullpointerException" answer in no way solved this problem. I know what a null pointer exception is. Why is a reference to an mp3 file in libGdx, in Android studio, creating a null pointer exception.
So I am doing the Brent Aureli's Code School tutorial of making flappy bird with libGdx. I am on video 14. https://www.youtube.com/watch?v=EaOE8rFa_8Q At 2:50 in the video he shows his code for this. I keep getting this error : "LwjglApplication: Couldn't initialize audio, disabling audio" when running the program after I add the libGdx "Music" object. Here is the full error list. Everything above "Exception in thread "LWJGL Application" java.lang.NullPointerException" Has already been showing up but the app still ran. Now it is getting this null pointer exception at the line:
music = Gdx.audio.newMusic(Gdx.files.internal("music.mp3"));
in the create() method. I have looked everywhere for an answer to this. I tried to copy and paste the mp3 manually into the raw directory or assets directory. That doesn't work. And here: Why does android studio not recognize .wav / .mp3 files, is a good example of how this problem is being handled. My code:
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.mygdx.game.states.GameStateManager;
import com.mygdx.game.states.MenuState;
public class FlappyDemo extends ApplicationAdapter {
public static final int WIDTH = 480;
public static final int HEIGHT = 800;
public static final String TITLE = "Flappy Bird";
private GameStateManager gsm;
private SpriteBatch batch;
Texture img;
private Music music;
@Override
public void create () {
batch = new SpriteBatch();
gsm = new GameStateManager();
music = Gdx.audio.newMusic(Gdx.files.internal("music.mp3"));
music.setLooping(true);
music.setVolume(0.1f);
music.play();
gsm.push(new MenuState(gsm));
Gdx.gl.glClearColor(1, 0, 0, 1);
}
@Override
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
gsm.update(Gdx.graphics.getDeltaTime());
gsm.render(batch);
}
@Override
public void dispose () {
batch.dispose();
img.dispose();
music.dispose();
}
}
All the png files in assets work just fine. Also any mp3's I put in Android Studio have a "?" symbol as the icon If anyone has any idea it would be much appreciated.