[英]Android Java Calendar getDisplayName/s returning null
timeOfMark = Calendar.getInstance(Locale.ENGLISH);
Map<String, Integer> what = timeOfMark.getDisplayNames(Calendar.HOUR, Calendar.SHORT, Locale.ENGLISH);
for(Map.Entry<String, Integer> pair : what.entrySet())
{
Log.e(pair.getKey(), Integer.toString(pair.getValue()));
}
This case crashes my android app, because Log.e cannot accept null string. 这种情况崩溃我的Android应用程序,因为Log.e不能接受空字符串。
It is same thing with 与此同样如此
timeOfMark.getDisplayName(Calendar.HOUR, Calendar.SHORT, Locale.ENGLISH);
I tried many variations with input parameters. 我用输入参数尝试了很多变化。 For locale I also did Locale.getDefault() and many other.
对于语言环境,我也做了Locale.getDefault()等等。 Still same * *
还是一样* *
No darn luck. 没有运气。 Is there anything to solve this?
有什么可以解决的吗? Or a easy workaround?
还是一个简单的解决方法?
public Map getDisplayNames(int field,int style,Locale locale)
public Map getDisplayNames(int field,int style,Locale locale)
This method returns a Map containing all display names in style and locale and their field values, or null
if no string representation is available. 此方法返回包含样式和区域设置中所有显示名称及其字段值的Map,如果没有可用的字符串表示形式,则返回
null
。
timeOfMark.getDisplayName(Calendar.HOUR, Calendar.SHORT, Locale.ENGLISH);
There is not String representation of HOUR, ie you can express HOURS
in string
like we did for MONTH And DAY_OF_WEEK 没有HOUR的字符串表示,即你可以像我们为MONTH和DAY_OF_WEEK所做的那样用
string
表示HOURS
Try WEEK, MONTH Example 试试WEEK,MONTH示例
Map< String, Integer> representations =
now.getDisplayNames(Calendar.MONTH, Calendar.ALL_STYLES, locale);
You will get 你会得到
{Apr=3, April=3, Aug=7, August=7, Dec=11, December=11, Feb=1, February=1, Jan=0, January=0, Jul=6, July=6, Jun=5, June=5, Mar=2, March=2, May=4, Nov=10, November=10, Oct=9, October=9, Sep=8, September=8}
For Calendar.DAY_OF_WEEK 对于Calendar.DAY_OF_WEEK
{Fri=6, Friday=6, Mon=2, Monday=2, Sat=7, Saturday=7, Sun=1, Sunday=1, Thu=5, Thursday=5, Tue=3, Tuesday=3, Wed=4, Wednesday=4}
Try here 试试这里
http://www.browxy.com/SubmittedCode/18596 http://www.browxy.com/SubmittedCode/18596
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.