13

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

this is my simple code

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

as per java doc

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

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)

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)
7
  • Can you add the stacktrace and mention which JDK version are you running? Commented Oct 6, 2012 at 17:06
  • @Augusto:i have updated my post, have a look. Commented Oct 6, 2012 at 17:09
  • I can reproduce the problem with Java 1.7 for the currency codes you mentioned. Commented Oct 6, 2012 at 17:10
  • @roelandvanbeek:that's strange!! seems like those are not supported currency codes under ISO 4217. Commented Oct 6, 2012 at 17:13
  • Just check your currencies against Currency.getAvailableCurrencies(). On my box TMT is available, the others are not. Commented Oct 6, 2012 at 17:14

3 Answers 3

7

This is an interesting problem.

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.

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.

Sign up to request clarification or add additional context in comments.

1 Comment

please see my edit. TMT is a new code, so it makes sense that is not available on java 6
1

For Uruguay UYU is working fine instead of UYI and COP instead of COU for Columbia TMT is not working for me also.

1 Comment

yes its there in my list and for this its working fine.i am not sure about UYI though
0

EDITED: For me this works:

 Currency curr = java.util.Currency.getInstance("UYU");
 System.out.println("Currency code:" + curr.getCurrencyCode());

UYI is not in the ISO 4217 standard, here is a list: http://www.xe.com/iso4217.php

1 Comment

Can you try with this line of code java.util.Currency.getInstance("UYI"); and update what is the outcome?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.