我正在尝试创建一个xml文件阅读器。我在JFrame中使用eclipse制作了主要的xml文件,并编写了如下的文件读取器代码;java中的XML文件阅读器
public xml() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 486, 533);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnopen = new JButton("Open");
btnopen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int returnVal = fc.showOpenDialog(contentPane);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
{
File file = fc.getSelected();
textFirst.setText(file.getAbsolute("XML", "xml"));
StaxParser read = new StaxParser();
List<Student> readStudents = read.readStudents(file.getAbsolutePath());
for (Student student : readStudents) {
textOutput.append(student+"\n\n");
}
}
catch (Exception e) {
//TODO Auto-generated catch block
e.printStackTrace();
textOutput.append("\nError");
}
} else {
textOutput.setText("user cancelled operation");
}
}
});
我收到一个错误的地方,它说,
File file = fc.getSelected();
我得到的错误是这个;
http://gyazo.com/10d739192c178e04a085bd392e93139b
是否有任何特定的原因,你正试图建立一个XML阅读器?因为有很多不同的产品适合各种需求。 –
@CeilingGecko事实上有......这是我的课程任务。如果我只能使用互联网上的许多xml读取器之一,那么为什么我会在这里请求关于我当前的xml读取器代码的指导? – MrShazzyMan
那么什么是堆栈跟踪? –