*
The moose likes Beginning Java and the fly likes java.util.*; Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.util.*;" Watch "java.util.*;" New topic
Author

java.util.*;

Charlie Petrie
Greenhorn

Joined: Jun 26, 2002
Posts: 10
I'm just trying to figure out how to use the methods in the Currency class... Here's some code that won't compile:
import java.util.*;
public class CurrencyTest {
String s;
public static void main(String []args){
CurrencyTest ct = new CurrencyTest();
ct.printSymbol();
}
public void printSymbol(){
s = Currency.getSymbol(Locale.FRENCH);
System.out.println(s);
}
}
Can anybody help with this? Thanks.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
It will help if you show us the error message you get from the compiler.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
shiv hari
Greenhorn

Joined: Aug 01, 2002
Posts: 9
The method getSymbol() in the class Currency is not defined as static and hence it cannot be referenced as you are trying to. Only menthods and members that are defined as static can be accessed by a class name.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
shivc,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Charlie Petrie
Greenhorn

Joined: Jun 26, 2002
Posts: 10
Thanks shivc...
The thing is is that I tried a few different combinations to get that method to work but to no avail. I realize that this method returns a String but the code I originally had still results in a compiler error. Here's the code I tried and then the error code:
import java.util.*;
public class CurrencyTest {
String s;
String z;
public static void main(String []args){
CurrencyTest ct = new CurrencyTest();
ct.printSymbol();
}
public void printSymbol(){
s = z.getSymbol(Locale.FRENCH);
System.out.println(s);
}
}

C:\Java\Practice Code\CurrencyTest.java:11: cannot resolve symbol
symbol : method getSymbol (java.util.Locale)
location: class java.lang.String
s = z.getSymbol(Locale.FRENCH);
^
1 error
Tool completed with exit code 1

Obviously I just don't have a clue how to implement this methods. This is really bugging me. Can you set me straight here? Thanks.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Since z is a String, z.getSymbol() means "call the getSymbol() method of the String class". Only problem is, there isn't any such method in the String class.
shiv hari
Greenhorn

Joined: Aug 01, 2002
Posts: 9
Probably what you want can be achieved by the following code. This is just one way of doing it.
import java.util.*;
public class CurrencyTest {
String s;
public static void main(String []args)
{
CurrencyTest ct = new CurrencyTest();
ct.printSymbol();
}
public void printSymbol()
{
Currency c=Currency.getInstance(Locale.US);
s = c.getSymbol(Locale.US);
System.out.println(s);
}
}
The Currency class does not have any constructor, but the static method getInstance() gives you a reference to the Currency object. You need specify your static Locale member as the arguement, then you can use the getSymbol method to get the symbol.
Hope this helps!
Charlie Petrie
Greenhorn

Joined: Jun 26, 2002
Posts: 10
Thanks shiv hari. That's exactly what I wanted.
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
I've been following this thread because I am a beginner, too and wanted to know how it was done. However, my program compiles, but generates an error and my questions are:
1. Exception in class main NoClassDefFoundError: java/util/Currency at CurrencyTest.printSymbol ,etc. Any guesses as to what might be wrong?
2. How does one pipe the errors to either a file or something which will let me cut and paste the results? I tried:
java CurrencyTest > results.txt but I ended up with an empty file.
Thanks! Janet
Rodney Woodruff
Ranch Hand

Joined: Dec 04, 2001
Posts: 80
Janet,
Can we see the code that is causing the error?


Hope This Helps
shiv hari
Greenhorn

Joined: Aug 01, 2002
Posts: 9
Janet,
1. You are getting the excpetion of ClassNotFound maybe because you are not using the right JDK version. The Currency class is present in the 1.4 and not in 1.2. Just check your JDK version by giving the command java -version on the command prompt.
2. You get the errors redirected to a file using 2> instead of >. The pipe > will redirect only the output of command to the file whereas the 2> pipe will redirect the errors.
Hope this helps!
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
Shiv Hari-
1. I tried 2 > and I ended up with the same results (no output to the file - just an empty file).
2. Now, here was something "amusing" , I looked at the version (I used java -version) and you are right, it looks like I have 1.3 but the amusing part is that I downloaded the 1.4 sdk (file name: j2sdk-1_4_0_01-windows-i586.exe, with file version of 2.11.15, dates of the readme files were 04/20/02) and even re-installed it just now and it still shows up as 1.3!?!? Release notes from the re-install state 1.4! Here's a sample from the readme file:
README
Java(TM) 2 SDK, Standard Edition
Version 1.4.0
I hesistated downloading a beta version from Sun's site - any recommendations?
Thanks for your help!
=====
To Rodney - I just cut and pasted Shiv's code which he posted on this message thread.
Thanks!
[ August 15, 2002: Message edited by: Janet Wilson ]
Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
Previous to you installing the 1.4 SDK did you have the 1.3 installed? Did you uninstall the 1.3 before installing the 1.4? Also check your classpath. On my box I had a problem because it was using the JRE (C:\Program Files\JavaSoft\JRE\1.3.1_02) instead of the JDK.


Greg Ostravich - SCPJ2
shiv hari
Greenhorn

Joined: Aug 01, 2002
Posts: 9
Janet,
did u try 2>, I mean 2 and > without a space. If you give 2 followed by a space and then >, it will result in a blank output file.
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
Greg,
I wish it was this simple. I did not have the JRE installed before. According to the documentation I read, I would not want a classpath to be set. My PATH is set to the location of j2...\bin and I am able to compile the code.
Does that help?
Janet
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
Shiv,
Thanks for clarifying that. The piping now works but so much for my program... Here are my results:
java.lang.NoClassDefFoundError: java/util/Currency
at CurrencyTest.printSymbol(CurrencyTest.java:13)
at CurrencyTest.main(CurrencyTest.java:8)
Exception in thread "main"
Thanks a bunch! Janet
shiv hari
Greenhorn

Joined: Aug 01, 2002
Posts: 9
Janet,
Looks like you are still struggling with the right JDK version. Do you have ur 1.4 jar in the classpath ? Ensure this, then I am sure the program will run. I tried it myself

shiv.
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
Shiv,
You are right, I am struggling with the version and as a result, I made a new thread to help out with the issue.
As for the classpath, I have been playing around with that. According to Sun I shouldn't have to include it, however, what was intesting is that
when I did NOT have the classpath my program execution resulted in:
java.lang.NoClassDefFoundError: java/util/Currency
at CurrencyTest.printSymbol(CurrencyTest.java:13)
at CurrencyTest.main(CurrencyTest.java:8)
Exception in thread "main"
when I DID have the classpath defined as C:\j2sdk1.4.0_01, my program execution resulted in:
java.lang.NoClassDefFoundError: CurrencyTest
Exception in thread "main"
So, your help has been MOST appreciated by this newbie as it helped me diagnose where my problems exist.
Thanks! Janet
Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
Janet,
I think you're almost there. It does make sense that you'd need the classpath. I'm not sure why you wouldn't want to do that.
Now if you just add "." to the classpath for the current directory everything should work.
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
Greg,
Thanks for your words of encouragement.
You said I needed to include a period. My classpath is set (w/in the environment variables section of control panel/system) to:
C:\j2sdk1.4.0_01
Where does the period go? You also said something about current directory - I'm unsure what you are referring to.
I have a separate directory off the C root called: janets-java. I do my program compilations and executions from there.
Sorry for being such a dim bulb. What should be a very easy concept I'm made a mountain out of it!
Thanks for putting up with this! Janet
Bryant Constant
Greenhorn

Joined: Jun 24, 2002
Posts: 10

Following is the CLASSPATH to use:
.;C:\j2sdk1.4.0_01
The dot (.) represents the current directory in Windows and Unix. The CLASSPATH (or any other PATH) is a list of directories to look at to resolve which class (or program) to use. The directories are separated by semilcolons ( ; ). The list is evaluated from left to right.
[ August 16, 2002: Message edited by: Bryant Constant ]
Janet Wilson
Ranch Hand

Joined: Jul 16, 2002
Posts: 98
VICTORY!!!
I do not have to pull my hair out anymore! Thanks to everyone I am back in business and a much happier person.
THANKS to everyone who helped out!!! Janet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.util.*;