简体   繁体   中英

Trying to get DAY_OF_WEEK from calendar causes Resource Not Found

I am trying to find the day of the week by:

Calendar cd = Calendar.getInstance();
int dow = cd.get(Calendar.DAY_OF_WEEK);

But whenever I load the program I get a

Unable to Start Activity android.content.res.Resources$NotFound Exception: String resource ID #0x5

And 0x5 corresponds to Thursday, today, in the Calendar resource I think.

How can I solve this problem?

I think you are trying to update view with that int value which is not true (because setText method isn't overloaded for int type), you need to make array of strings like that

private static final String[] WEEK = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

and use it

textView.setText(WEEK[cal.get(Calendar.DAY_OF_WEEK)]);

尝试删除gen文件夹或使用以下方法清理项目:Project-> Clean,然后重试。

Does it have to be with calendar? There's other methods out there that doesn't involve the calendar to get the current day of the week..

edit:

<uses-permission
  android:name="android.permission.READ_CALENDAR">
 </uses-permission>
<uses-permission
   android:name="android.permission.WRITE_CALENDAR">
   </uses-permission>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM