开发者

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 prog开发者_如何学Goram 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?


Try to delete the gen folder or clean the project using: Project-> Clean and try again.


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>


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)]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜