我是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);
}
}
这是logcat
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)。
任何形式的帮助都表示赞赏。
答案 0 :(得分:1)
得到了!! FriendPickerFragment的实例需要初始化
friendPickerFragment=(FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);