Send app request to facebook friends in Android-Collection of common programming errors

I am trying to send app request to fb friends but failed to do.I have tried the Hackbook sample code.but i am not getting any request.

Here is the code:

 Bundle params = new Bundle();
          params.putString("message", "Learn how to make your Android apps social");         
          Utility.mFacebook.dialog(Hackbook.this, "apprequests", params,new AppRequestsListener());

public class AppRequestsListener extends BaseDialogListener {
        @Override
        public void onComplete(Bundle values) {
            Toast toast = Toast.makeText(getApplicationContext(), "App request sent",Toast.LENGTH_SHORT);
            toast.show();
        }

        @Override
        public void onFacebookError(FacebookError error) {
            Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast toast = Toast.makeText(getApplicationContext(), "App request cancelled",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    }

Using the Above code toast message is showing but i am not getting any request.

I have tried another code too..

here is the code:

private void sendRequestDialog() {
        Bundle params = new Bundle();
        params.putString("message",
                "Learn how to make your Android apps social");

        WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
                Hackbook.this, Session.getActiveSession(), params))
                .setOnCompleteListener(new OnCompleteListener() {
                    @Override
                    public void onComplete(Bundle values,
                            FacebookException error) {
                        if (error != null) {
                            if (error instanceof FacebookOperationCanceledException) {
                                Toast.makeText(
                                        Hackbook.this.getApplicationContext(),
                                        "Request cancelled", Toast.LENGTH_SHORT)
                                        .show();
                            } else {
                                Toast.makeText(
                                        Hackbook.this.getApplicationContext(),
                                        "Network Error", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        } else {
                            final String requestId = values
                                    .getString("request");
                            if (requestId != null) {
                                Toast.makeText(
                                        Hackbook.this.getApplicationContext(),
                                        "Request sent", Toast.LENGTH_SHORT)
                                        .show();
                            } else {
                                Toast.makeText(
                                        Hackbook.this.getApplicationContext(),
                                        "Request cancelled", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        }
                    }
                }).build();
        requestsDialog.show();
    }

Using this above code i am getting error:

09-18 14:42:50.102: E/InputEventReceiver(1310): Exception dispatching input event.
09-18 14:42:50.102: E/MessageQueue-JNI(1310): Exception in MessageQueue callback: handleReceiveCallback
09-18 14:42:50.142: E/MessageQueue-JNI(1310): java.lang.NullPointerException: Argument 'session' cannot be null
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.internal.Validate.notNull(Validate.java:29)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.widget.WebDialog$BuilderBase.(WebDialog.java:392)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.widget.WebDialog$RequestsDialogBuilder.(WebDialog.java:684)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.android.Hackbook.sendRequestDialog(Hackbook.java:520)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.android.Hackbook.onItemClick(Hackbook.java:230)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.widget.AdapterView.performItemClick(AdapterView.java:298)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.widget.AbsListView.performItemClick(AbsListView.java:1268)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.widget.AbsListView$PerformClick.run(AbsListView.java:3055)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3961)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.View.dispatchTouchEvent(View.java:7241)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1914)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2113)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1466)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.app.Activity.dispatchTouchEvent(Activity.java:2436)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2061)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.View.dispatchPointerEvent(View.java:7425)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3376)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3308)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4402)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4380)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4484)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.os.MessageQueue.nativePollOnce(Native Method)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.os.MessageQueue.next(MessageQueue.java:125)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.os.Looper.loop(Looper.java:124)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.app.ActivityThread.main(ActivityThread.java:4918)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at java.lang.reflect.Method.invokeNative(Native Method)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at java.lang.reflect.Method.invoke(Method.java:511)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at dalvik.system.NativeStart.main(Native Method)
09-18 14:42:50.152: D/AndroidRuntime(1310): Shutting down VM
09-18 14:42:50.152: W/dalvikvm(1310): threadid=1: thread exiting with uncaught exception (group=0x40ef7438)

Could somebody help me out.@Thanks

  1. WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(Hackbook.this, Session.getActiveSession(), params))
    

    The error is that the session Variable is null..Please make sure you did initialised it correctly in the prior codes..

  2. I don’t see any code that initialize Session variable.

    The official facebook page from where you got your code says the following

    ” Prerequisites

    Before you begin, make sure you’ve already set up Facebook Login. This ensures you have the prerequisites and your app is ready for additional Facebook integration. “

    My guess is that user doesn’t have an active session. If it doesn’t ask you to log in to facebook or you are not already logged in then you won’t have a valid session which means the “Session.getActiveSession()” will return null.

  3. First see this link:

    Facebook Session

    also see this Android SDK for Facebook App Tutorial

    and have you tried this:

        
            
                
                    
                    
                
            
            
            
        
    

    where @string/app_id attribute of meta tag is defined in your string.xml

    edited:

    Try to search sessionId where is storing and where is used.

    Maybe you have problem to storing sessionId and getting error while fetching current sessionId

    Happy Coding 🙂

Originally posted 2013-11-27 12:25:07.