0

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! :)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Eron
  • 81
  • 9
  • That question, you're linking me, isn't really helpful to me. – Eron Feb 14 '18 at 18:45
  • I need an soluion for interfaces, all these answers are for Classes or Objects, but I'm dealing with android specific code as I said... – Eron Feb 14 '18 at 18:46

0 Answers0