-1

I'm trying to learn and add some basic Facebook functionality to my Android App (an address book). What I'm eventually going to do is import a friends profile picture. I've currently only copy/pasted what I need from the "FriendPickerSample" example project, which is just a button that brings up a friend picker fragment, and, if I remember correctly, it places the names you picked into a list. I've altered it to come up when an imageview is clicked, and it'll just Toast the single name that is chosen. When I try to bring up the friend picker, I get a null pointer exception, and I don't understand why. Here's the log:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.JDE.RAB/com.JDE.RAB.PickFriendsActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.facebook.widget.PickerFragment.onCreateView(PickerFragment.java:152)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523)
at com.JDE.RAB.PickFriendsActivity.onStart(PickFriendsActivity.java:112)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
at android.app.Activity.performStart(Activity.java:3781)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
... 11 more

This is the code in my onclick, which is supposed to open the PickFriendsActivity:

if (Session.getActiveSession() == null || Session.getActiveSession().isClosed())
        {
        Session.openActiveSession(AddNewTabLayoutActivity.this, true, null);
        }//endif                
FriendPickerApplication application = (FriendPickerApplication) GetMyApplication();
application.setSelectedUsers(null);

Intent intent = new Intent(AddNewTabLayoutActivity.this, PickFriendsActivity.class);
// Note: The following line is optional, as multi-select behavior is the default for
// FriendPickerFragment. It is here to demonstrate how parameters could be passed to the
// friend picker if single-select functionality was desired, or if a different user ID was
// desired (for instance, to see friends of a friend).

//multi-select is OFF
PickFriendsActivity.populateParameters(intent, null, false, true);
Debugger.SendNotification(getApplicationContext(), "Alert", "Alert", "Starting Activity For Result", 3009);
startActivityForResult(intent, 2);

PickFriendsActivity, line 112 is super.onStart(); Should I post the entirety of that activities source code?

Thanks for any help!

1 Answers1

0

You should copy res/layout/pick_friends_activity.xml to your own project too.

Zhenghong Wang
  • 2,117
  • 17
  • 19
  • Try clean and build your project again? – Zhenghong Wang Jan 21 '14 at 08:24
  • Well, maybe you should paste your main activity's code here. And try rebuild FacebookSDK project, too. :) – Zhenghong Wang Jan 21 '14 at 08:43
  • Okay, I've added some code to the original question. I hope that helps, because I'm not really sure what else I should add, beyond copy/pasting the entire source code for PickFriendsActivity. Also, I have the FacebookSDK project built as a .jar (with 1.6) in my project , and the android-support-v4.jar is included as well. – Jake JediMastr Ellis Jan 21 '14 at 22:34
  • Have you included FacebookSDK as a library project, not a .jar file? – Zhenghong Wang Jan 22 '14 at 07:47
  • No, I exported the SDK as a .jar (built with 1.6, not 1.7), and added it to my build path that way. It's been awhile since I first got the SDK, but I recall having problems trying to link it as a library project. If I remember correctly, the problem was that the SDK was only available at compile time, and was not being exported with the .apk, despite being checked to export. I seem to remember researching other people having that problem, and the solution was to add it as a .jar. – Jake JediMastr Ellis Jan 22 '14 at 08:02
  • I made a test in FacebookSDK's newest version 3.6, it works perfectly. And the document says that you should import it as a library project. – Zhenghong Wang Jan 22 '14 at 08:19
  • Okay, I've updated my SDK to the latest version, and got it to include as a library instead of a .jar, but I'm still getting the same NullPointerException, unfortunately. – Jake JediMastr Ellis Jan 22 '14 at 20:31
  • I just made my own test project, and it's giving me a completely different error. NoClassDefFoundError for com.facebook.Session. When I build it, it tells me that it can't find the apk for FacebookSDK. The original sample doesn't work anymore, either. It has the same problem now. – Jake JediMastr Ellis Jan 22 '14 at 23:16
  • Okay,I've finally gotten one of the samples working again.However,I had to make a new project & copy/paste all of the code and resources over,& it still wouldn't work.After trying new projects several times,I finally got it to work by building and launching the completely blank project before even adding the FacebookSDK to it. Otherwise,com.facebook.widget.LoginButton would fail to instantiate in the layout,which prevented me from even building it.Now, my only problem is the key hash.As far as I can see,the keyhash it tells me it's using is correct,except for one character."_" should be "/". – Jake JediMastr Ellis Jan 25 '14 at 20:01
  • I've gotten a new hash now, but it's still getting the key hash wrong. My current key hash has a + symbol in it, and ends with an = sign. That's the hash that Logcat gives me, through the code here (http://stackoverflow.com/questions/4388992/key-hash-for-android-facebook-app). When I try to post a status update, the hash in the error that it toasts has a - symbol instead of a +, and does not end with an = sign. I am not able to add this hash to my Sample App settings on developers.facebook. Any ideas? I've pretty much run out... – Jake JediMastr Ellis Jan 27 '14 at 03:48
  • Are you working on Sample App which contains in Facebook's SDK, or a new app by yourself? They need different hashes. Check the document here. https://developers.facebook.com/docs/android/getting-started – Zhenghong Wang Jan 27 '14 at 04:11
  • I was originally working on my own app, but have been trying to get one of the sample apps working again since I updated the SDK. I've finally gotten it to accept the key hash, so I'm going to get back to working on my own app again now that I've proven the SDK is set up correctly. Getting back to my app, I no longer receive the NullPointerException, and everything is now working perfectly (after I fixed a Session error). Thank you for all of your help Zhenghong! – Jake JediMastr Ellis Jan 28 '14 at 05:29