0

i don't know what's wrong with my code. As long as i know my code is right, but i still got java.lang.null.pointer in

friendPickerFragment.loadData(false);

i already defined friendPickerFragment like this but still, i got error

friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);

Here is my whole code and i think it's the same as facebook sdk sample friendpicker

public class PickFriends extends FragmentActivity {

FriendPickerFragment friendPickerFragment;

public static void populateParameters(Intent intent, String userId, boolean multiSelect, boolean showTitleBar){
    intent.putExtra(FriendPickerFragment.USER_ID_BUNDLE_KEY,userId);
    intent.putExtra(FriendPickerFragment.MULTI_SELECT_BUNDLE_KEY, multiSelect);
    intent.putExtra(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY,showTitleBar);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pick_friends);

    FragmentManager fragmentManager = getSupportFragmentManager();

    if(savedInstanceState == null){
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        fragmentManager.beginTransaction()
                .add(R.id.friend_picker_fragment, friendPickerFragment);
        //friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);
    } else {
        friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFriends.this.onError(error);
        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {
            SelectFriend application = (SelectFriend) getApplication();
            application.setSelectedUsers(friendPickerFragment.getSelection());

            setResult(RESULT_OK,null);
            finish();
        }
    });
}

private void onError(Exception error){
    String text = "Error Exception";
    Toast toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
    toast.show();
}

@Override
protected void onStart(){
    super.onStart();
    friendPickerFragment.loadData(false);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_pick_friends, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

Please help me. Thank you

  • See http://stackoverflow.com/questions/23788666/how-to-get-a-list-of-all-user-friends – Gokhan Caglar Apr 25 '15 at 16:02
  • @GokhanCaglar i already have friends that installed my application. But it seems still got error on part friendPickerFragment.loadData(false). I'm sorry i'm newbie – Monika Maytri Apr 26 '15 at 02:00
  • You said you are getting a null pointer, are you getting this because friendPickerFragment is null in your onStart call? If so have you ensured it is being set correctly in your onCreate() before onStart() is called? Have any details you can provide about the null pointer exception? – tehspark May 01 '15 at 23:34
  • everybody, thank you for your answer. It's already resolve – Monika Maytri May 04 '15 at 18:41

0 Answers0