为了账号安全,请及时绑定邮箱和手机立即绑定

尝试调用虚拟方法(片段中的问题视图)

尝试调用虚拟方法(片段中的问题视图)

慕尼黑5688855 2021-10-06 10:41:04
ChatFragment.java:public class ChatFragment extends Fragment {private FirebaseListAdapter<ChatMessage> adapter;View RootView;EmojiconEditText emojiconEditText;ImageView emojiButton,submitButton;EmojIconActions emojIconActions;@Nullable@Overridepublic View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {    View RootView = inflater.inflate(R.layout.fragment_chat,container,false);    this.RootView = RootView;    return RootView;}@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {    super.onCreate(savedInstanceState);//:55    emojiButton = (ImageView)this.RootView.findViewById(R.id.emoji_button);    submitButton = (ImageView)this.RootView.findViewById(R.id.submit_button);    emojiconEditText = (EmojiconEditText)this.RootView.findViewById(R.id.emojicon_edit_text);    emojIconActions = new EmojIconActions(getActivity().getApplicationContext(),this.RootView,emojiButton,emojiconEditText);    emojIconActions.ShowEmojicon();错误:Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference    at dev.edmt.chatapp.ChatFragment.onCreate(ChatFragment.java:55)//:60    emojIconActions = new EmojIconActions(getActivity().getApplicationContext(),this.RootView,this.emojiButton,this.emojiconEditText);    emojIconActions.ShowEmojicon();错误:Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void hani.momanii.supernova_emoji_library.Helper.EmojiconEditText.setOnFocusChangeListener(android.view.View$OnFocusChangeListener)' on a null object reference    at hani.momanii.supernova_emoji_library.Actions.EmojIconActions.setFocusListener(EmojIconActions.java:241)    at hani.momanii.supernova_emoji_library.Actions.EmojIconActions.<init>(EmojIconActions.java:64)    at dev.edmt.chatapp.ChatFragment.onCreate(ChatFragment.java:60)
查看完整描述

2 回答

?
天涯尽头无女友

TA贡献1831条经验 获得超9个赞

移动这段代码:


 emojIconActions = new EmojIconActions(getActivity().getApplicationContext(),this.RootView,this.emojiButton,this.emojiconEditText);

    emojIconActions.ShowEmojicon();

以onCreateView法之前return RootView;


查看完整回答
反对 回复 2021-10-06
  • 2 回答
  • 0 关注
  • 128 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信