简体   繁体   English

Android Java Calendar getDisplayName / s返回null

[英]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.

相关问题 为什么java.util.Currency.getDisplayName()返回null - Why is java.util.Currency.getDisplayName() returning null calendar.getDisplayName 返回错误的日期 - calendar.getDisplayName returning the wrong day 日历getDisplayName返回utf-8 - Calendar getDisplayName to return utf-8 Firebase google authentication getCurrentUser.getEmail() 返回 null,但它的返回值为 getCurrentUser.getDisplayName() - Firebase google authentication getCurrentUser.getEmail() returns null, but its returning value for getCurrentUser.getDisplayName() 摘要日历返回null - Abstract Calendar returning null &#39;Calendar.getDisplayName&#39;提供&#39;IllegalArgumentException&#39;和&#39;Unknown Source&#39; - 'Calendar.getDisplayName' giving 'IllegalArgumentException' with 'Unknown Source' Calendar.getDisplayName()的工作日有误 - Wrong weekdays from Calendar.getDisplayName() Java:Android:MediaPlayer有时会在onResume上返回null - Java: Android: MediaPlayer sometimes returning null onResume BufferedReader在Android应用程序中返回null,但在Java应用程序中不返回null - BufferedReader returning null in Android application but not in Java application Android Java:片段在onCreateView()中返回空视图 - Android Java: Fragments returning null view in onCreateView()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM