2

Is all in the title, I do not understand the problem this time is a bit different, I used the same Object(List) for two different programs and it does not work in the second time, see :

private void jMenuItem23ActionPerformed(java.awt.event.ActionEvent evt) {                                            
init_creer_client();
List  items  = new ArrayList();
items.add("mawren");
items.add("blabla");
items.add("Bonjour");

CL.show(cartes,"creer_client");       
}   

screenshot about the error : enter image description here

by cons here its work smoothly :

 import java.awt.Dimension;
 import java.awt.HeadlessException;
 import java.util.ArrayList;
 import java.util.List;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

 public class Test_swingx extends JFrame {

public Test_swingx(String title) throws HeadlessException {

this.setTitle(title);
JPanel pan=new JPanel();
JTextField jtf=new JTextField();
jtf.setColumns(20);
List items  = new ArrayList();
items.add("hello");
items.add("marwen");
items.add("allooo");
AutoCompleteDecorator.decorate(jtf, items,false);
pan.add(jtf);
this.setContentPane(pan);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setBounds(280, 150, 500, 200);

}


 public static void main(String[] args) {

Test_swingx tsx=new Test_swingx("helloo swingx");

}
}

can anyone explain to me ?

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Marwen Trabelsi
  • 4,167
  • 8
  • 39
  • 80

6 Answers6

4

You have a java.awt.List import should be java.util.List

3

It's because the List on the left-hand side is a java.awt.List instead of a java.util.List.

Try changing the line to:

java.util.List items = new ArrayList();

This is probably happening because you're importing java.awt.* and java.util.List. If you can change how you import these classes, you can avoid namespacing the type inline.

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
1

Nope, compiles fine:

package cruft;

import java.util.ArrayList;
import java.util.List;

/**
 * ListExample description here
 * @author Michael
 * @link
 * @since 2/11/12 7:27 PM
 */
public class ListExample {

    public static void main(String[] args) {
        List items = new ArrayList();
        for (String arg : args) {
            items.add(arg);
        }
        System.out.println(items);
    }
}

Runs fine:

"C:\Program Files\Java\jdk1.7.0_02\bin\java" -Didea.launcher.port=7536 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 111.255\bin" -Dfile.encoding=UTF-8 -classpath . com.intellij.rt.execution.application.AppMain cruft.ListExample foo bar baz bat
[foo, bar, baz, bat]

Process finished with exit code 0
duffymo
  • 305,152
  • 44
  • 369
  • 561
0

Sanity check: Have you imported both import java.util.List and import java.util.ArrayList?

Joe
  • 15,669
  • 4
  • 48
  • 83
  • why List and ArrayList has to import seperately ? can i just import java.util.* ? tks inadvance ! :D – Adams.H Feb 19 '14 at 03:58
  • You can, but if you just want List and ArrayList there's little point in importing all of the other stuff in there when you're not going to use it :) – Joe Feb 19 '14 at 09:16
  • actually , if i wanna upcasting ArrayList to List , i have to do the import seperately . if not , it says "Type mismatch: cannot convert from ArrayList to List" , this error keeps showing until i import List and ArrayList Seperately ... tks for you reply ! – Adams.H Feb 19 '14 at 09:41
0

Check your imports, because java.awt.List is not the same as java.util.List.

rtheunissen
  • 7,347
  • 5
  • 34
  • 65
0

I think the confusion comes from having two List types in different packages, as the error message says. You don't give all the code that generates the error, but I think a reasonable start to a fix would be to change the highlighted line to:

java.util.List items  = new ArrayList();

and make sure you have imported java.util.*

snim2
  • 4,004
  • 27
  • 44