libGDX:处理特定于平台的代码

时间:2018-02-14 15:30:57

标签: android nullpointerexception libgdx share sharing

我正在使用带有libGDX的AndroidStudio,并希望将我在游戏中获得的分数分享到社交网络(WhatsApp,Facebook,电子邮件等)。我甚至成功地这样做了,但我有一个致命的问题。作为帮助,我在GitHub上使用了那篇文章:https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code

我在我的代码中带来了该文章的所有内容

并在我的主要活动中添加了这个:

 Leaderboard leaderboard;

public PlayState(Leaderboard leaderboard) {
    super(nplatform);

    this.leaderboard = leaderboard;

    leaderboard.shareScore();
}

但我想在gameover-screen中单击一个按钮时调用该方法,因此在更新方法中不在构造函数中。但试图这样做

 @Override
public void update(float dt, Leaderboard leaderbord) {

leaderboard.shareScore();   // The code behind that isn't important  }

我收到了这个错误:

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)

这些链接都把我带到了“leaderboard.shareScore();”的部分。是

如果有办法将代码带入更新方法,我将非常感激

感谢您提供有用的答案! :)

0 个答案:

没有答案