My application got crashed because of not initializing the view

后端 未结 3 353
孤独总比滥情好
孤独总比滥情好 2021-01-29 15:07

Here, i am trying to call setText method but my application is getting crashed because of some initialization problem.

EditText edittext;
    SharedPreferences          


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 15:42

    edittext is not initialized. Initialize it in onCreate.

    In onCreate you have

    edittext.setText(returnString); // not initialized in onCreate
    

    You have

    edittext =(EditText)findViewById(R.id.edit_message); // initialized in sendMessage
    

    in sendMessage. So you may be setting text to edittext even before it is initialized

提交回复
热议问题