1

我是 Android 新手,我正在为我的应用程序使用 Facebook SDK。我想动态显示好友列表(使用FriendPickerFragment类)。这是我showfriendpicker()在单击按钮时调用的方法,但是每当我单击该按钮时,应用程序就会停止。我没有得到什么是错误。

private void showfriendpicker()
    {
         FragmentManager manager = getSupportFragmentManager();
         Fragment fragmentToShow = null;
         Bundle args = getIntent().getExtras();
         friendPickerFragment = new FriendPickerFragment(args);
             // friendPickerFragment =  (FriendPickerFragment)
         manager.findFragmentById(R.id.picker_fragment);

    Fragment  fragment = manager.findFragmentById(R.id.picker_fragment);
                if (fragment == null) {

                    FragmentTransaction ft = manager.beginTransaction();
                    ft.add(R.id.picker_fragment, friendPickerFragment);
                    Fragment  fragment1 = manager.findFragmentById(R.id.picker_fragment);
                   ft.show(fragment1);
                    ft.commit(); 
                     friendPickerFragment.loadData(false);
                    }

    } 

这是日志猫

         07-17 08:06:34.394: E/AndroidRuntime(828): java.lang.NullPointerException
          07-17 08:06:34.394: E/AndroidRuntime(828):    at                     
          com.facebook.widget.PickerFragment.loadData(PickerFragment.java:475)
          07-17 08:06:34.394: E/AndroidRuntime(828):    at          
         com.example.fblogin1.MainActivity.showfriendpicker(MainActivity.java:221)
        07-17 08:06:34.394: E/AndroidRuntime(828):  at               
          com.example.fblogin1.MainActivity.access$2(MainActivity.java:199)
          07-17 08:06:34.394: E/AndroidRuntime(828):    at     
      com.example.fblogin1.MainActivity$3.onClick(MainActivity.java:63)
       07-17 08:06:34.394: E/AndroidRuntime(828):   at       
        android.view.View.performClick(View.java:4202)
        07-17 08:06:34.394: E/AndroidRuntime(828):  at  
         android.view.View$PerformClick.run(View.java:17340)
       07-17 08:06:34.394: E/AndroidRuntime(828):   at            
       android.os.Handler.handleCallback(Handler.java:725)
       07-17 08:06:34.394: E/AndroidRuntime(828):   at       
        android.os.Handler.dispatchMessage(Handler.java:92)
           07-17 08:06:34.394: E/AndroidRuntime(828):   at       
                  android.os.Looper.loop(Looper.java:137)
           07-17 08:06:34.394: E/AndroidRuntime(828):   at           
       android.app.ActivityThread.main(ActivityThread.java:5039)
       07-17 08:06:34.394: E/AndroidRuntime(828):   at  
          java.lang.reflect.Method.invokeNative(Native Method)
          07-17 08:06:34.394: E/AndroidRuntime(828):    at   
         java.lang.reflect.Method.invoke(Method.java:511)
       07-17 08:06:34.394: E/AndroidRuntime(828):   at 
      com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      07-17 08:06:34.394: E/AndroidRuntime(828):    at     
        com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        07-17 08:06:34.394: E/AndroidRuntime(828):  at   
       dalvik.system.NativeStart.main(Native Method)
      07-17 08:06:37.816: I/Process(828): Sending signal. PID: 828 SIG: 9

friendPickerFragment.loadData(false);它在调用时显示错误

我在我的activity_main.xml(id=picker_fragment) 中添加了一个框架布局。任何形式的帮助表示赞赏。

4

1 回答 1

1

知道了 !!FriendPickerFragment 的实例需要初始化 2

 friendPickerFragment=(FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
于 2013-07-18T04:39:47.980 回答