与 SSCE 一起链接到编译错误的粘贴:http: //pastebin.com/upYzbHN1
文件名是“foo.java”。用'javac foo.java'编译。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.HashMap;
import java.util.List;
public class foo extends JFrame {
HashMap<Integer,Thing> Things = new HashMap<Integer,Thing>();
JTextPane jtp = new JTextPane();
public void findThings() {
SwingWorker<HashMap<Integer,Thing>,Thing> sw1 = new SwingWorker<HashMap<Integer,Thing>,Thing>() {
protected HashMap<Integer,Thing> doInBackground() {
HashMap<Integer,Thing> things = new HashMap<Integer,Thing>();
Thread.sleep(1000);
return things;
}
protected void process(List<Thing> chunks) {
for(Thing thing : chunks) {
this.things.put(thing.id, thing);
this.jtp.setText(String.valueOf(this.things.size()));
}
}
};
sw1.execute();
}
public foo() {
super();
setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton jbtn = new JButton("findThings()");
jbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
findThings();
}
});
add(jbtn);
this.jtp.setPreferredSize(new Dimension(300,300));
add(this.jtp);
setLocationRelativeTo(null);
pack();
setVisible(true);
}
public static void foo(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new foo();
}
});
}
private class Thing {
public Thing() {
id = 100;
name = "Thing's name";
}
Integer id = null;
String name = null;
}
}
给出这些编译错误:
foo.java:21: error: cannot find symbol
this.things.put(thing.id, thing);
^
symbol: variable things
foo.java:22: error: cannot find symbol
this.jtp.setText(String.valueOf(this.thi
ngs.size()));
^
symbol: variable things
foo.java:22: error: cannot find symbol
this.jtp.setText(String.valueOf(this.thi
ngs.size()));
^
symbol: variable jtp
3 errors