1 Reply Latest reply: Jan 15, 2014 4:57 PM by rp0428 RSS

    Trying to create a custom resource bundle shows error

    998899-Oracle

      Hi all,

       

      I am using jdev12c.

      I tried to create the following class

       

      package view;
      
      
      import java.awt.Dimension;
      
      
      import java.util.ListResourceBundle;
      
      
      public class Resource extends ListResourceBundle {
          protected Object[][] getContents() {
                  return new Object[][] = {
                  // LOCALIZE THIS
                      {"s1", "Le disque \"{1}\" {0}."},          // MessageFormat pattern
                      {"s2", "1"},                               // location of {0} in pattern
                      {"s3", "Mon disque"},                      // sample disk name
                      {"s4", "ne contient pas de fichiers"},     // first ChoiceFormat choice
                      {"s5", "contient un fichier"},             // second ChoiceFormat choice
                      {"s6", "contient {0,number} fichiers"},    // third ChoiceFormat choice
                      {"s7", "3 mars 1996"},                     // sample date
                      {"s8", new Dimension(1,3)}                 // real object, not just string
                  // END OF MATERIAL TO LOCALIZE
                  };
              }
          }
      
      

       

      The code is copied from java documentation ListResourceBundle (Java Platform SE 7 )

       

      Looks like a documentation bug where "=" has to be removed

        • 1. Re: Trying to create a custom resource bundle shows error
          rp0428
          The code is copied from java documentation ListResourceBundle (Java Platform SE 7 )

          No - that code is not a copy of that Java documentation.

           

          The code at that link compiles just fine. You have modified the code.

          Looks like a documentation bug where "=" has to be removed

          No - looks like you have added "=" and caused the error you are probably complaining about.

           

          The code in the API is a constructor; it is constructing a new object. You don't use "=" in a constructor; you use "=" when you are making an assignment.

           

          Review the 'Anonymous Classes trail in The Java Tutorials

          http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html

          The following example, HelloWorldAnonymousClasses, uses anonymous classes in the initialization statements of the local variables frenchGreeting and spanishGreeting,
          . . .
                   HelloWorld frenchGreeting = new HelloWorld() {

                      String name = "tout le monde";

                      public void greet() {

                          greetSomeone("tout le monde");

                      }

                      public void greetSomeone(String someone) {

                          name = someone;

                          System.out.println("Salut " + name);

                      }

                  };

          That 'new HelloWorld() {' is constructing a new instance of an anonymous class. Note that the ONLY time "=" is used in that example is for the assignments.

           

          Message was edited by: Moderator. No SHOUTING please