列表项 = new ArrayList() :它不起作用
都在标题里了 我不明白这次的问题有点不同,我对两个不同的程序使用了相同的对象(列表),但第二次不起作用,请参阅:
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");
}
有关错误的屏幕截图:
通过 cons 这里,它的工作顺利:
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");
}
}
任何人都可以向我解释一下吗?
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 :
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您有一个 java.awt.List 导入应该是 java.util.List
You have a java.awt.List import should be java.util.List
这是因为左侧的
List
是java.awt.List
而不是java.util.List
。尝试将该行更改为:
发生这种情况可能是因为您正在导入
java.awt.*
和java.util.List
。如果您可以更改导入这些类的方式,则可以避免内联类型的命名空间。It's because the
List
on the left-hand side is ajava.awt.List
instead of ajava.util.List
.Try changing the line to:
This is probably happening because you're importing
java.awt.*
andjava.util.List
. If you can change how you import these classes, you can avoid namespacing the type inline.不,编译良好:
运行良好:
Nope, compiles fine:
Runs fine:
健全性检查:您是否同时导入了
import java.util.List
和import java.util.ArrayList
?Sanity check: Have you imported both
import java.util.List
andimport java.util.ArrayList
?检查您的导入,因为
java.awt.List
与java.util.List
不同。Check your imports, because
java.awt.List
is not the same asjava.util.List
.我认为混乱来自于不同包中的两个
List
类型,正如错误消息所述。您没有提供生成错误的所有代码,但我认为修复的合理开始是将突出显示的行更改为:并确保您已导入
java.util.*
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:and make sure you have imported
java.util.*