Java Question Problems passing an Activity Parameter to sdk

DevBaby

Active Member
Licensed User
Longtime User
I am making a call to a sdk call that requires an Activity parameter. I thought that ba.Activity would work (I am passing final BA ba in my call). I am using @ActivityObject in my class.

The call opens an authorization dialog, however an error happens before the dialog ever opens.

The library code is fairly long (with other calls etc), but i have narrowed the Nullexceptionerror error down to the following...

B4X:
fb.authorize(ba.activity, new String[] {"publish_stream","read_friendlists"}, new DialogListener() { 
         
            @Override
            public void onCancel() {
               
            }
            
            @Override
            public void onComplete(Bundle values) {
            
               Editor editor = sp.edit(); 
               editor.putString("Access_Token", fb.getAccessToken());
               editor.putLong("Expires", fb.getAccessExpires());
               editor.commit();
            
               if(DialogType == "feed"){
                  
                  showfeed(ba);
                  
               }else{
                  
                  apprequest(ba);
               }
               
            }

            @Override
            public void onError(DialogError derror) {
         
         
               
            }
            
            @Override
            public void onFacebookError(FacebookError ferror) {
            
         
               
            }
            
         
         });
 
Last edited:

DevBaby

Active Member
Licensed User
Longtime User
PackageAdded: package:am.gameplus.pkg
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (inappbillingservice) Create **
Could not bind to service.
BillingSupported: false
** Service (inappbillingservice) Start **
main_fbbuttons_click (B4A line: 9463)
fb.FeedDialog(AppId,"","","feed")
java.lang.NullPointerException
at com.facebook.android.FbDialog.onCreate(FbDialog.java:86)
at android.app.Dialog.dispatchOnCreate(Dialog.java:312)
at android.app.Dialog.show(Dialog.java:230)
at com.facebook.android.Facebook.dialog(Facebook.java:840)
at com.facebook.android.Facebook.startDialogAuth(Facebook.java:369)
at com.facebook.android.Facebook.authorize(Facebook.java:232)
at com.facebook.android.Facebook.authorize(Facebook.java:148)
at com.fb.share.fbshareclass.FeedDialog(fbshareclass.java:78)
at am.gameplus.pkg.main._fbbuttons_click(main.java:4128)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:124)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:850)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
 

warwound

Expert
Licensed User
Longtime User
You're calling fb.authorize from an Activity module on a Button click are you?
(You're not calling it from the inappbillingservice?)

If so i'd guess that the NullPointerException relates to something other than your Activity reference.
Can you add some Log statements to your DialogListener?

B4X:
fb.authorize(ba.activity, new String[] {"publish_stream","read_friendlists"}, new DialogListener() { 
            
                @Override
                public void onCancel() {
                    Log.d("B4A", "DialogListener onCancel");
                }
                
                @Override
                public void onComplete(Bundle values) {
                    Log.d("B4A", "DialogListener onComplete");
                    Editor editor = sp.edit(); 
                    editor.putString("Access_Token", fb.getAccessToken());
                    editor.putLong("Expires", fb.getAccessExpires());
                    editor.commit();
                
                    if(DialogType == "feed"){
                      Log.d("B4A", "DialogListener showfeed");
                        showfeed(ba);
                        
                    }else{
                      Log.d("B4A", "DialogListener apprequest");
                        apprequest(ba);
                    }
                    
                }

                @Override
                public void onError(DialogError derror) {
                    Log.d("B4A", "DialogListener onError");
                }
                
                @Override
                public void onFacebookError(FacebookError ferror) {
                    Log.d("B4A", "DialogListener onFacebookError");
                    
                }
            
            });

What gets logged before the NullPointerException?

Martin.
 

DevBaby

Active Member
Licensed User
Longtime User
Thanks for your reply...

Yes, I am launching the facebook method from a button in b4a. I added the log statements you gave me, but I get the same log report and error.

I am running my app and immediately trying the facebook method. I am using my kindle fire that does not support inappbilling, so that is why that message appears in the log. However the log above is exaclty what appears in my console.
 

warwound

Expert
Licensed User
Longtime User
Don't any of the added log statements get executed (and display something) before the null pointer exception?
Do you mean none of the added log statements ever execute?

Martin.
 

DevBaby

Active Member
Licensed User
Longtime User
Yes they were never executed in looking at the error log, I went to the sdk java files at com.facebook.android.FbDialog.onCreate(FbDialog.ja va:86) and noticed that there was a refercence error in that class because the sdk was not built correctly in eclipse.

Sdks are easy to work with when give a .jar file, but facebook gives src file that you have to import and then elcipse builds additional file (like a r.java for drawable ids) so needless to say I was able to get past that hurdle, but then another issue arose that I will start a new thread.

Thanks for your help.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…