What is false in my program that gives “App keeps stopping” while opening that activity?

前端 未结 2 1917
别跟我提以往
别跟我提以往 2021-01-29 14:57

Application open normal but while opening this activity it says \"App keeps stopping\". I don\'t understand what is the problem. Maybe API level is not compatible with calendar.

2条回答
  •  既然无缘
    2021-01-29 15:46

    You cannot set this code outside of OnCreate method. Because your layout has not been created yet, you cannot findViewById since they activity has no content. You must setContentView before you do anything regarding your views that will be added to your activity.

    final EditText etDate=(EditText) findViewById(R.id.etDate);
    

    Set these objects without initializing them, and then initialize in your onCreate after you setContentView(LAYOUT);

    EditText etDate;
    
    public void onCreate(Bundle savedIntanceState) {
        ....
    
        etDate = findViewById(R.id.etDate);
    

提交回复
热议问题