Android facebook Feed对话框未显示

时间:2012-12-14 21:36:09

标签: android facebook

当我点击按钮时,应用程序停止了。

public class MainActivity extends ListActivity {   
        private  Facebook mFacebook;

Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
        dialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                postToWall();
            }
        });
        dialog.show();     
    }
 public void postToWall() {
Bundle parameters = new Bundle();
        parameters.putString("description", "description about link");
        parameters.putString("picture","link of picture your want add with share post.");
        parameters.putString("link", "Link you want to share");
        parameters.putString("name","Name of link");
        parameters.putString("caption","describe your caption text");

            mFacebook.dialog(this, "stream.publish", parameters,new DialogListener() {

                @Override   
                public void onFacebookError(FacebookError arg0) {
                }

                public void onError(DialogError arg0) {
                }

                public void onComplete(Bundle arg0) {
                }

                public void onCancel() {
                }
            });
         }

堆栈跟踪:

12-14 21:26:11.198: E/AndroidRuntime(1021): FATAL EXCEPTION: main
12-14 21:26:11.198: E/AndroidRuntime(1021): java.lang.NullPointerException
12-14 21:26:11.198: E/AndroidRuntime(1021):     at com.example.imdb.Display.postToWall(Display.java:447)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at com.example.imdb.Display$1.onClick(Display.java:399)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at android.view.View.performClick(View.java:4202)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at android.view.View$PerformClick.run(View.java:17340)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at android.os.Handler.handleCallback(Handler.java:725)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at android.os.Looper.loop(Looper.java:137)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at android.app.ActivityThread.main(ActivityThread.java:5039)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at java.lang.reflect.Method.invokeNative(Native Method)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at java.lang.reflect.Method.invoke(Method.java:511)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-14 21:26:11.198: E/AndroidRuntime(1021):     at dalvik.system.NativeStart.main(Native Method)

另外,有一个警告说不推荐使用Facebook类型的方法对话框(Context,String,Bundle,Facebook.DialogListener)。这有关系吗?如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

mFacebook可能是空的。看看吧。

答案 1 :(得分:1)

您的mFacebook对象为空,您应该mFacebook = new Facebook ("yourappIDString")。您必须将appID传递给构造函数 另外,要回答您的弃用问题,Facebook source说明

  

应该使用新代码        Session来管理会话状态,        Request发出API请求,

因此,如果您想保持合规,则需要重写一些代码。