猿问

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

ChatFragment.java:


public class ChatFragment extends Fragment {

private FirebaseListAdapter<ChatMessage> adapter;

View RootView;

EmojiconEditText emojiconEditText;

ImageView emojiButton,submitButton;

EmojIconActions emojIconActions;

@Nullable

@Override

public 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;

}


@Override

public 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)


慕尼黑5688855
浏览 130回答 2
2回答

天涯尽头无女友

移动这段代码:&nbsp;emojIconActions = new EmojIconActions(getActivity().getApplicationContext(),this.RootView,this.emojiButton,this.emojiconEditText);&nbsp; &nbsp; emojIconActions.ShowEmojicon();以onCreateView法之前return RootView;
随时随地看视频慕课网APP

相关分类

Java
我要回答