textView setText() NullPointerException

前端 未结 3 1404
伪装坚强ぢ
伪装坚强ぢ 2021-01-22 12:13

I have an almost completely Vanilla App. All I\'m trying to do is change the text of a textView, but it gives me a NullPointerException. I have no XML configuration, no added me

3条回答
  •  长情又很酷
    2021-01-22 13:06

    You are giving setContentView() the wrong layout if your XML is actually declared as fragment_main. That is why the controls are currently null.

    // The layout file is not correct.
    setContentView(R.layout.activity_second);
    

提交回复
热议问题