Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在Facebook上共享时获取空指针异常_Android_Facebook - Fatal编程技术网

Android 在Facebook上共享时获取空指针异常

Android 在Facebook上共享时获取空指针异常,android,facebook,Android,Facebook,我将以下代码用于FaceBook共享。图片发布在某些FaceBook ID中,但对于某些FaceBook ID我遇到空指针异常。我如何解决此问题 postParams.putString("message", message); postParams.putString("picture",picture); System.out.println("******* 111111 *********"); com.facebook.Request.Callback cal

我将以下代码用于
FaceBook
共享。图片发布在某些FaceBook ID中,但对于某些
FaceBook ID
我遇到空指针异常。我如何解决此问题

   postParams.putString("message", message);
   postParams.putString("picture",picture);
   System.out.println("******* 111111 *********");

   com.facebook.Request.Callback callback = new  com.facebook.Request.Callback()
    {
     public void onCompleted(Response response)
      {
         JSONObject graphResponse =response.getGraphObject().getInnerJSONObject();
         String postId = null;
         try {
         postId = graphResponse.getString("id");
         } catch (JSONException e) 
         {
         Log.i("postthis", "JSON error " + e.getMessage());
         }
         FacebookRequestError error = response.getError();
         if (error != null) {
            Log.i("postthis", "JSON error "     +error.getErrorMessage());
            } 
         else {
//       Toast.makeText(ctx.getApplicationContext(), postId,
//                       Toast.LENGTH_LONG).show();
          }
          }
          };
这是
logcat
错误:

01-22 09:43:20.812: E/AndroidRuntime(5201): FATAL EXCEPTION: main
01-22 09:43:20.812: E/AndroidRuntime(5201): java.lang.NullPointerException
01-22 09:43:20.812: E/AndroidRuntime(5201):     at FBLogin$2.onCompleted  (FBLogin.java:316)
01-22 09:43:20.812: E/AndroidRuntime(5201):     at com.facebook.Request$4.run(Request.java:1669)
01-22 09:43:20.812: E/AndroidRuntime(5201):     at android.os.Handler.handleCallback(Handler.java:615)
01-22 09:43:20.812: E/AndroidRuntime(5201):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-22 09:43:20.812: E/AndroidRuntime(5201):     at android.os.Looper.loop(Looper.java:137)
01-22 09:43:20.812: E/AndroidRuntime(5201):     at android.app.ActivityThread.main(ActivityThread.java:4895)
01-22 09:43:20.843: E/android.os.Debug(353): !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error

在墙上张贴的会话为空,因此存在空指针异常。您必须先激活会话才能在墙上张贴。您可以使用以下代码在墙上共享

   Session.openActiveSession(activity, true, new Session.StatusCallback() {

    // callback when session changes state
    @Override
    public void call(Session session, SessionState state,
            Exception exception) {
        if (session != null && session.isOpened()) {

            // Check for publish permissions
            List<String> permissions = session.getPermissions();
            if (!isSubsetOf(PERMISSIONS, permissions)) {
                Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
                        activity, PERMISSIONS);
                session.requestNewPublishPermissions(newPermissionsRequest);
                return;
            }

            Bundle postParams = new Bundle();
            postParams.putString("message", message);

                postParams.putString("tags",tag);
                     postParams.putString("place",place_id);



            Request.Callback callback = new Request.Callback() {
                private String toastmessage;

                public void onCompleted(Response response) {
                    try {
                        JSONObject graphResponse = response
                                .getGraphObject().getInnerJSONObject();
                        String postId = null;

                        postId = graphResponse.getString("id");
                    } catch (Exception e) {
                        Log.i("Test", "JSON error " + e.getMessage());
                    }
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        isPosted(false);
                        Toast.makeText(
                                activity.getApplicationContext(),
                                error.getErrorMessage(),
                                Toast.LENGTH_SHORT).show();
                    } else {
                        isPosted(true);
                        toastmessage = "Posted Successfully";
                        Toast.makeText(activity, toastmessage,
                                Toast.LENGTH_SHORT).show();
                        {

                        }
                    }
                }
            };

            Request request = new Request(session, "me/feed",
                    postParams, HttpMethod.POST, callback);

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
        }


    }
});
Session.openActiveSession(activity,true,new Session.StatusCallback()){
//会话更改状态时的回调
@凌驾
公共无效调用(会话、会话状态、,
例外情况(例外情况){
if(session!=null&&session.isOpened()){
//检查发布权限
List permissions=session.getPermissions();
如果(!isSubsetOf(权限、权限)){
Session.newpermissions请求newpermissions请求=newsession.newpermissions请求(
活动、权限);
session.requestNewPublishPermissions(newPermissionsRequest);
返回;
}
Bundle postParams=新Bundle();
postParams.putString(“消息”,消息);
postParams.putString(“tags”,tag);
postParams.putString(“place”,place\u id);
Request.Callback=new Request.Callback(){
私人字符串演讲信息;
未完成公共无效(响应){
试一试{
JSONObject graphResponse=响应
.getGraphObject().getInnerJSONObject();
字符串postId=null;
postId=graphResponse.getString(“id”);
}捕获(例外e){
Log.i(“Test”,“JSON error”+e.getMessage());
}
FacebookRequestError=response.getError();
if(错误!=null){
显示(假);
Toast.makeText(
activity.getApplicationContext(),
错误。getErrorMessage(),
吐司。长度(短)。show();
}否则{
显示(正确);
toastmessage=“已成功发布”;
Toast.makeText(活动、toastmessage、,
吐司。长度(短)。show();
{
}
}
}
};
请求=新请求(会话“me/feed”,
postParams,HttpMethod.POST,callback);
RequestAsyncTask任务=新的RequestAsyncTask(请求);
task.execute();
}
}
});

在这个链接中给出了一次尝试,这对我在Android sdk 3.x中的工作是有效的

 void publishToWall(Session session) {      
    if (session != null)  {          
        Bundle postParams = new Bundle();
        postParams.putString("message", "contentStr");
        postParams.putString("description",  "description");
        postParams.putString("link", "");
        postParams.putString("name", "Name");
        postParams.putString("picture", "picture url");

        Request.Callback callback = new Request.Callback()  {
            public void onCompleted(Response response)  {       

            }
        };
        Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
        RequestAsyncTask task = new RequestAsyncTask(request);
        task.execute();             

        Log.i("TAG", "Message posted to your facebook wall!..");         


    }           
 }

检查您的参数,如果其中任何一个参数为空,则图形对象在facebook共享中显示空值。

将日志猫与行号一起发布。我发布了日志猫,有人能帮我吗..第316行的代码是什么?如果(FBLogin.facebook.isSessionValid()),这是上述给定代码中的行您可以使用以下链接共享获取此错误{响应:响应代码:500,graphObject:null,错误:{HttpStatus:500,错误代码:341,错误类型:FacebookApiException,错误消息:已达到应用程序请求限制。},isFromCache:false}行内JSONObject graphResponse=response.getGraphObject().getInnerJSONObject();我使用的代码与您发布的代码相同。。但facebook的墙上什么也没贴。我该怎么办???