I'm using AndroidStudio with libGDX and want to share the score I got in my game to social networks (WhatsApp, Facebook, E-Mail, ect.). I even succeed in doing so, but I have a fatal problem. As help I used that article on GitHub: https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code
I brought everything of that article in my code
and added this in my main Activity:
Leaderboard leaderboard;
public PlayState(Leaderboard leaderboard) {
super(nplatform);
this.leaderboard = leaderboard;
leaderboard.shareScore();
}
But I want to call the method, when clicking on a button in gameover-screen, so in update method not in constructor. But trying to do so
@Override
public void update(float dt, Leaderboard leaderbord) {
leaderboard.shareScore(); // The code behind that isn't important }
I got that error:
E/AndroidRuntime: FATAL EXCEPTION: GLThread 1152
Process: com.demo.game, PID: 29103
java.lang.NullPointerException: Attempt to invoke interface method 'void com.demo.game.NativePlatform.shareScore()' on a null object reference
at com.demo.game.PlayState.update(PlayState.java:245)
at com.demo.game.states.GameStateManager.update(GameStateManager.java:32)
at com.demo.game.RiskyDemo.render(RiskyDemo.java:37)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:459)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1553)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1253)
the links are all bringing me to the part where "leaderboard.shareScore();" is.
If there is a way to bring the code in update method, I would be very grateful
Thanks for helpful answers! :)