Solved

ResourceBundle not found

Posted on 2004-10-19
24
316 Views
Last Modified: 2012-06-27
Hi experts,

I have a java program and two .properties files which are myResource.properties and myResource_ms_MY.properties. 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(resourceBundle.getString("Cancel"));


      }
}

myResources.properties

Cancel=CancelDetails
Enter=EnterDetails
Delete=DeleteDetails

myResources_ms_MY.properties

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.NoClassDefFoundError: ResourceBundle

How can i rectify it? Thanks
0
Comment
Question by:ricjava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 9
  • 3
  • +1
24 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12355514
ResourceBundle is part of the java sdk. Apparently that can't be found.
Have a thorough read of http://mindprod.com/jgloss/classpath.html
0
 
LVL 7

Expert Comment

by:grim_toaster
ID: 12355571
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.
0
 

Author Comment

by:ricjava
ID: 12355574
i'm using jdk1.4
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 6

Expert Comment

by:expertmb
ID: 12355585
there is no locale called "ms"
0
 

Author Comment

by:ricjava
ID: 12355607
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?
0
 

Author Comment

by:ricjava
ID: 12355623
i thought "ms" is valid ISO lang code for malay and "MY" is valid iso code for Malaysia...........i'll check..
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12355638
>>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.
0
 

Author Comment

by:ricjava
ID: 12355662
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.

0
 

Author Comment

by:ricjava
ID: 12355670
I thought classpath is set if we import any java classes that are not part of Java API.
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12355681
this what i got when i ran your example

Exception in thread "main" java.util.MissingResourceException: Can't find bundle
 for base name myResource, locale ms_MY
        at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle
.java:837)
        at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:806)
        at java.util.ResourceBundle.getBundle(ResourceBundle.java:577)
        at ResourceBundleResearch.main(ResourceBundleResearch.java:14)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12355685
>>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 ?
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12355690
>>When i run the java program, i get

0
 

Author Comment

by:ricjava
ID: 12355708
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.....

0
 
LVL 37

Expert Comment

by:zzynx
ID: 12355711
How do you run it?
0
 

Author Comment

by:ricjava
ID: 12355726
i just run from C

C:\myprogram\java ResourceBundle

0
 

Author Comment

by:ricjava
ID: 12355730
hope this time my problem won't be a tougher exam question for students :)
0
 
LVL 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 12355751
Try
        C:\myprogram\java -classpath . ResourceBundle
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12355761
>>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



0
 
LVL 37

Expert Comment

by:zzynx
ID: 12355768
I think that's your problem

Don't start it as

        C:\myprogram\java ResourceBundle

but as

        C:\myprogram\java ResourceBundleResource
0
 

Author Comment

by:ricjava
ID: 12355811
sorry.........i didn't start with

c:\myprogram\java ResourceBundle

but

c:\myprogram\java ResourceBundleResearch
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12355822
Did you already try

        C:\myprogram\java -classpath . ResourceBundleResource

?
0
 

Author Comment

by:ricjava
ID: 12355858
Thanks:)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12355886
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)
0
 

Author Comment

by:ricjava
ID: 12355905
zzyn,

oh yes....should be your second last comment:)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add projects t working set in maven 2 68
web project error add remove 1 83
How to log java errors in tomcat 8 38
Firefox and firebub 5 27
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question