java中的XML文件读取器

java中的XML文件读取器,java,xml,file,windowbuilder,Java,Xml,File,Windowbuilder,我正在尝试创建一个xml文件读取器。我在JFrame中使用eclipse制作了主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(c

我正在尝试创建一个xml文件读取器。我在JFrame中使用eclipse制作了主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");
}
}
});
我得到的错误是:

http://gyazo.com/10d739192c178e04a085bd392e93139b

我想你弄错了,试试看

File file = fc.getSelectedFile()

根据链接中的例外情况,您缺少一些导入,例如:

文件无法解析为类型
丢失

import java.io.File;
import java.util.List;
列表无法解析为缺少的类型

import java.io.File;
import java.util.List;
等等。 尝试为该异常中提到的所有类添加正确的导入


而且,正如@Gaurav Joseph提到的,您使用了错误的方法来获取文件。

您尝试构建XML读取器有什么特别的原因吗?因为已经有很多适合不同需求的产品了。@CeilingGecko是的,事实上有。。。这是我的课程作业。如果我能够在internet上使用众多xml阅读器中的一个,为什么我要在这里询问有关xml阅读器当前代码的指导?那么堆栈跟踪是什么呢?我已经对代码进行了此更改,现在我在public static void main(String[]args)行上遇到错误{即使该行代码旁边没有红色的x,检查该行代码是否有任何错误。@GauravYes没有名为getSelected的方法。请参考以下内容:对于其余错误,请使用导入
import java.io.File;
import java.util.List;
还导入学生类cod无论你把它放在哪里。