ricjava
asked on
ResourceBundle not found
Hi experts,
I have a java program and two .properties files which are myResource.properties and myResource_ms_MY.propertie s. All there three files are in c:\myprogram folder.
The java program
import java.util.*;
public class ResourceBundleResearch
{
public static void main(String[] args)
{
Locale locale1, locale2;
ResourceBundle resourceBundle;
locale1 = Locale.getDefault();
locale2 = new Locale("ms", "MY");
resourceBundle = ResourceBundle.getBundle(" myResource ", locale2);
System.out.println(resourc eBundle.ge tString("C ancel"));
}
}
myResources.properties
Cancel=CancelDetails
Enter=EnterDetails
Delete=DeleteDetails
myResources_ms_MY.properti es
Cancel=Batal
Enter=Masuk
Delete=Padam
I have set the classpath to C:\myprogram
When i run the java program, i get
Exception in thread "main" java.lang.NoClassDefFoundE rror: ResourceBundle
How can i rectify it? Thanks
I have a java program and two .properties files which are myResource.properties and myResource_ms_MY.propertie
The java program
import java.util.*;
public class ResourceBundleResearch
{
public static void main(String[] args)
{
Locale locale1, locale2;
ResourceBundle resourceBundle;
locale1 = Locale.getDefault();
locale2 = new Locale("ms", "MY");
resourceBundle = ResourceBundle.getBundle("
System.out.println(resourc
}
}
myResources.properties
Cancel=CancelDetails
Enter=EnterDetails
Delete=DeleteDetails
myResources_ms_MY.properti
Cancel=Batal
Enter=Masuk
Delete=Padam
I have set the classpath to C:\myprogram
When i run the java program, i get
Exception in thread "main" java.lang.NoClassDefFoundE
How can i rectify it? Thanks
Which JDK are you using? ResourceBundle has been around since JDK 1.1, do you have an older JDK installed that it's using? To find out, at the command prompt do:
java -version
If you have an old one (possibly installed by windows), ensure that a newly downloaded versions location is first in the path.
java -version
If you have an old one (possibly installed by windows), ensure that a newly downloaded versions location is first in the path.
ASKER
i'm using jdk1.4
there is no locale called "ms"
ASKER
zzynx - I don't have to do any with my classpath, isn't it? Since ResourceBundle is part of java API.......
Anyone can copy and paste my codes to run?
Anyone can copy and paste my codes to run?
ASKER
i thought "ms" is valid ISO lang code for malay and "MY" is valid iso code for Malaysia...........i'll check..
>>ResourceBundle is part of java API
Indeed. But apparently the java API classes can't be found.
And that has to do with your class path, yes.
Indeed. But apparently the java API classes can't be found.
And that has to do with your class path, yes.
ASKER
expertmb - yes "ms" is a valid ISO language code in http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
zzynx - remember that day i run the Properties class and that can be found. If properties can be found then why not ResourceBundle. They are from java api.
zzynx - remember that day i run the Properties class and that can be found. If properties can be found then why not ResourceBundle. They are from java api.
ASKER
I thought classpath is set if we import any java classes that are not part of Java API.
this what i got when i ran your example
Exception in thread "main" java.util.MissingResourceE xception: Can't find bundle
for base name myResource, locale ms_MY
at java.util.ResourceBundle.t hrowMissin gResourceE xception(R esourceBun dle
.java:837)
at java.util.ResourceBundle.g etBundleIm pl(Resourc eBundle.ja va:806)
at java.util.ResourceBundle.g etBundle(R esourceBun dle.java:5 77)
at ResourceBundleResearch.mai n(Resource BundleRese arch.java: 14)
Exception in thread "main" java.util.MissingResourceE
for base name myResource, locale ms_MY
at java.util.ResourceBundle.t
.java:837)
at java.util.ResourceBundle.g
at java.util.ResourceBundle.g
at ResourceBundleResearch.mai
>>I thought classpath is set
the class path is never set automatically.
>>remember that day i run the Properties class and that can be found.
Did you also run it
- the same way
- in c:\myprogram ?
the class path is never set automatically.
>>remember that day i run the Properties class and that can be found.
Did you also run it
- the same way
- in c:\myprogram ?
>>When i run the java program, i get
ASKER
zzynx - i was able to run Properties class that day without having any CLASSPATH created as env var in my computer.
Did you also run it
- the same way
- in c:\myprogram ?
absolutely.....
Did you also run it
- the same way
- in c:\myprogram ?
absolutely.....
How do you run it?
ASKER
i just run from C
C:\myprogram\java ResourceBundle
C:\myprogram\java ResourceBundle
ASKER
hope this time my problem won't be a tougher exam question for students :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>just run from C
>>C:\myprogram\java ResourceBundle
I hope you meant
C:\myprogram\java ResourceBundleResource // Your class is called ResourceBundleRESOURCE !!!!
Then try
C:\myprogram\java -classpath . ResourceBundleResource
>>C:\myprogram\java ResourceBundle
I hope you meant
C:\myprogram\java ResourceBundleResource // Your class is called ResourceBundleRESOURCE !!!!
Then try
C:\myprogram\java -classpath . ResourceBundleResource
I think that's your problem
Don't start it as
C:\myprogram\java ResourceBundle
but as
C:\myprogram\java ResourceBundleResource
Don't start it as
C:\myprogram\java ResourceBundle
but as
C:\myprogram\java ResourceBundleResource
ASKER
sorry.........i didn't start with
c:\myprogram\java ResourceBundle
but
c:\myprogram\java ResourceBundleResearch
c:\myprogram\java ResourceBundle
but
c:\myprogram\java ResourceBundleResearch
Did you already try
C:\myprogram\java -classpath . ResourceBundleResource
?
C:\myprogram\java -classpath . ResourceBundleResource
?
ASKER
Thanks:)
Thanks for accepting.
You see, the first link wasn't that bad ;°)
I quote:
7. To run a HelloWorld.class app, in the default package in C:\MyDir, use
CD \MyDir
java.exe -classpath . HelloWorld
Btw, next time make sure you accept the right comment (ResourceBundleResource instead of ResourceBunde)
You see, the first link wasn't that bad ;°)
I quote:
7. To run a HelloWorld.class app, in the default package in C:\MyDir, use
CD \MyDir
java.exe -classpath . HelloWorld
Btw, next time make sure you accept the right comment (ResourceBundleResource instead of ResourceBunde)
ASKER
zzyn,
oh yes....should be your second last comment:)
oh yes....should be your second last comment:)
Have a thorough read of http://mindprod.com/jgloss/classpath.html