Why Android app crashes for initializing variable with findViewById(R.id.******) at the beginning of the class?

后端 未结 4 1412
萌比男神i
萌比男神i 2020-11-22 09:27

I was just testing input/output, there was no special purpose, this is the last code that had run successfully:

public class MainActivity extends AppCompatA         


        
4条回答
  •  长情又很酷
    2020-11-22 10:15

    Add this code

     EditText username =  findViewById(R.id.editText_Username);
     EditText password = findViewById(R.id.editText_Password);
     TextView inputdata = findViewById(R.id.textView_InputData);
     TextView welcome = findViewById(R.id.textView_Welcome);
     Button login = findViewById(R.id.button_Login);
     Button anotherLogin = findViewById(R.id.button_Login_Another);
    

    in

    onCreate(); 
    

    method after

    setContentView(R.layout.activity_main);
    

提交回复
热议问题