2017-04-08 16 views
-4
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    View fa = getView(); 

    ll = (LinearLayout)inflater.inflate(R.layout.chat_layout, container,false); 

    //return inflater.inflate(R.layout.chat_layout, container, false); 

    if (!UtilChat.checkConnection(getActivity())){ 
     UtilChat.initToast(getActivity(), "LOL"); 

    }else{ 
     bindViews(); 
     verificaUsuarioLogado(); 
     mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) 
       .enableAutoManage(getActivity(), this) 
       .addApi(Auth.GOOGLE_SIGN_IN_API) 
       .build(); 
    } 
    return ll; 
} 
    private void bindViews(){ 
    contentRoot = fa.findViewById(R.id.contentRoot); 
    edMessage = (EmojiconEditText)fa.findViewById(R.id.editTextMessage); 
    btSendMessage = (ImageView)fa.findViewById(R.id.buttonMessage); 
    btSendMessage.setOnClickListener(this); 
    btEmoji = (ImageView)fa.findViewById(R.id.buttonEmoji); 
    emojIcon = new EmojIconActions(getActivity(),contentRoot,edMessage,btEmoji); 
    emojIcon.ShowEmojIcon(); 
    rvListMessage = (RecyclerView)fa.findViewById(R.id.messageRecyclerView); 
    mLinearLayoutManager = new LinearLayoutManager(getActivity()); 
    mLinearLayoutManager.setStackFromEnd(true); 
} 

錯誤:聊天火力地堡轉換成片段

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.v4.app.FragmentActivity.findViewById(int)' on a null object reference at sky.alien.korenovskguide.ChatActivity.bindViews(ChatActivity.java:381) at sky.alien.korenovskguide.ChatActivity.onCreateView(ChatActivity.java:125)

回答

0

這裏要調用findViewById空對象。

您在您的視圖fa上調用findViewById,這是錯誤的。

你必須使用

View myView = inflater.inflate(R.layout.chat_layout, container,false); 
TextView myText = myView.findViewById(R.id.my_Text_view);