抛出IllegalArgumentException的java.util.Currency.getInstance [英] java.util.Currency.getInstance throwing IllegalArgumentException

查看:148
本文介绍了抛出IllegalArgumentException的java.util.Currency.getInstance的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试使用 java.util.Currency ,但是对于几个货币代码,它抛出我 java.lang.IllegalArgumentException

I am just trying my hands around with java.util.Currency, but for few currency codes its throwing me java.lang.IllegalArgumentException

这是我的简单代码

java.util.Currency c = java.util.Currency.getInstance(code);

根据java doc

as per java doc


public static Currency getInstance(String currencyCode)

public static Currency getInstance(String currencyCode)



Returns the Currency instance for the given currency code.

Parameters:
    currencyCode - the ISO 4217 code of the currency 
Returns:
    the Currency instance for the given currency code 
Throws:
    NullPointerException - if currencyCode is null 
    IllegalArgumentException - if currencyCode is not a supported ISO 4217 code.

我收到这个例外的几个代码,其中很少是

I am getting this exception for few codes and few of them are


  1. UYI

  2. COU

  3. TMT

根据 ISO_4217

,以上所有代码均为官方ISO 4217货币名称,我不知道为什么我在这种情况下得到这个例外?
我是否需要做其他事情或需要将一些其他信息传递给JVM才能获得正确的值?
任何帮助清除我的困惑是非常明显的,或者可以指向我正在指向的 ISO 4217货币,因为我可以看到ISO 4217列表中的上述代码所以它可能我正在寻找错误的文件/参考文件。

as per ISO_4217, all above codes are official ISO 4217 currency names, i am not sure why i am getting this exception in this case? Do i need to do something else or need to pass some other information to JVM to get correct values? any help to clear my confusion is really appreciable or can point me to the ISO 4217 currency which java doc is pointing as i can see above codes in ISO 4217 list so its possible i am looking at wrong documents/references.

为了提供更多见解,这里是堆栈跟踪

In order to provide more insights here is the stack trace

Exception in thread "main" java.lang.IllegalArgumentException
    at java.util.Currency.getInstance(Unknown Source)
    at java.util.Currency.getInstance(Unknown Source)
    at CurrencyTest1.main(CurrencyTest1.java:10)



和Java版



and Java version

java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)


推荐答案

这是一个有趣的问题。

COU和UYI都不是真实货币。 COU是旧的委内瑞拉货币(不再使用),UYI是一种索引货币,可能被银行用来整理汇率。

Both COU and UYI are not real currencies. COU is the old Venezuelan currency (not in use anymore) and UYI is an indexed currency, probably used by banks to sort out exchange rates.

在java 1.7.0_u7中,当前 TMT 工作正常。 TMT于2009年推出,因此Java 6不知道该代码是有意义的。

In java 1.7.0_u7, the currecy TMT works fine. TMT was introduced in 2009, so it makes sense that Java 6 doesn't know that code.

这篇关于抛出IllegalArgumentException的java.util.Currency.getInstance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆