5

I am using this code to create a JList :

JList list = new JList<String>(new String[] {"Hello", "World"});

The program compiles and runs as well, on Eclipse Juno, but when I try to open it using WindowBuilder, it gives the following error :

new JList<String>(new String[] {"Hello", "World"}) is not valid source for component creation, it references not existing constructor. 

Now, since I am using Java 7(both JDK & JRE), this should not be an error.

Note : The rest of the program is correct.

JavaNewbie_M107
  • 2,007
  • 3
  • 21
  • 36

1 Answers1

0

I do not get any warnings with 'Java(TM) SE Runtime Environment (build 1.7.0_10-b18)' under Linux. This runs just fine:

    final JList list = new JList<String>(new String[] { "Hello", "World" });
    list.setSelectionInterval(0, 1);
    for (final Object o : list.getSelectedValuesList()) {
        System.out.println(o);
    }

However, you should use 'final JList list = ...' to have the proper generic argument supplied. This often causes problems.

Hint: activate compiler warnings, they often give you useful hints.

[Edit:] Because my code works, I guess that the problem DOES lie somewhere else, not in the part you mentioned above.

JayC667
  • 2,418
  • 2
  • 17
  • 31