ERROR

[Android Studio] Exception: Unable to start activity ComponentInfo{com.example.k_food_application/com.example.k_food_application.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.l..

파송송 2022. 10. 11. 11:56
728x90

원인

  • Layout id과 매칭이 안되어서 생긴 문제

위에 2줄 변수명, id 명이 맞는지 다시 확인하기

private TextView text_date;
text_date = (TextView) findViewById(R.id.Text_day);
text_date.setText(getDate());
public String getDate(){
    //날짜 처음엔 오늘 날짜 가져오기
    mNow = System.currentTimeMillis();
    Log.w("TEST: ", "test song1" );
    mDate = new Date(mNow);
    String getdate = mFormat.format(mDate);

    return getdate.toString();
}
728x90