1
我有一個libgdx項目,我想添加一個共享按鈕。我希望UI元素是一個libgdx,而共享邏輯由AddThis庫處理。libgdx項目中的Addthis.shareItem()拋出NullPointerException
我的Java代碼(libgdx UI)如下:
Button fb = createButton(50, 200, 0, "facebook.png"); //
stage.addActor(fb);
fb.addListener(new ClickListener()
{
@Override
public void clicked(InputEvent event, float x, float y)
{
super.clicked(event, x, y);
getApplicationListener().getNativeMethods().shareFb();
}
}
我不要在這兒貼createButton(),getApplicationListener()和getNativeMethods(),因爲我想單獨他們的名字說清楚他們在做什麼。 這裏是shareFb()方法:
public void shareFb()
{
handler.post(new Runnable()
{
@Override
public void run()
{
try
{
InputStream istr = context.getAssets().open("achievement1.png");
Bitmap imageBitmap = BitmapFactory.decodeStream(istr);
AddThis.shareItem(context, "facebook", "Achievement", "Completed level 1", imageBitmap);
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
}
});
}
然而,當我點擊我的UI按鈕時,shareItem()方法拋出一個NullPointerException異常,這裏的logcat的relevat部分:
09-23 17:29:37.912: E/AndroidRuntime(9491): Caused by: java.lang.NullPointerException
09-23 17:29:37.912: E/AndroidRuntime(9491): at com.addthis.core.sharer.ATFacebook.share(ATFacebook.java:53)
09-23 17:29:37.912: E/AndroidRuntime(9491): at com.addthis.ui.activities.ATShareActivity.startSharing(ATShareActivity.java:130)
09-23 17:29:37.912: E/AndroidRuntime(9491): at com.addthis.ui.activities.ATShareActivity.onCreate(ATShareActivity.java:74)
09-23 17:29:37.912: E/AndroidRuntime(9491): at android.app.Activity.performCreate(Activity.java:5451)
09-23 17:29:37.912: E/AndroidRuntime(9491): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
09-23 17:29:37.912: E/AndroidRuntime(9491): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
的與AddThis庫綁定的AddThisDemo項目工作正常,我複製了部分代碼,但這不是libgdx,所以它離我所需要的很遠。任何線索?