尝试在MAP片段中使用FAB的侦听器时出现NullPointerException

时间:2016-02-26 09:14:53

标签: android

这是错误消息

enter image description here

这是我的代码

enter image description here

1 个答案:

答案 0 :(得分:3)

您正试图在 fab 中找到 fab ,在 fab1 中找到 fab1 ... 您需要从片段的根视图中获取这些按钮。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) {
   View rootView = inflater.inflate(R.layout.carte_reseaux_fragment, container, false);
   fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
   .
   .
   Animation fab_open = AnimationUtils.loadAnimation(getContext(), R.anim.fab_open);
   //Actually FloatingActionButton has own implementation
   fab.setShowAnimation(fab_open);
   return rootView;
}