[英]XML file reader in java
I'm trying to create a xml file reader. 我正在尝试创建xml文件阅读器。 I've made the main xml file using eclipse within a JFrame and written the file reader code as below;
我已经在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");
}
}
});
I'm getting an error on the bit where it says; 我在说的地方有点错误;
File file = fc.getSelected();
The error I'm getting is this; 我得到的错误是这个;
http://gyazo.com/10d739192c178e04a085bd392e93139b
我想你试错了
File file = fc.getSelectedFile()
According to the exception in link, you are missing some imports, eg: 根据链接中的异常,您缺少一些导入,例如:
File cannot be resolved to a type
is missing File cannot be resolved to a type
为缺少File cannot be resolved to a type
import java.io.File;
List cannot be resolved to a type
is missing List cannot be resolved to a type
为缺少List cannot be resolved to a type
import java.util.List;
etc. Try to add correct import for all classes mentioned in that exception. 等等。尝试为该异常中提到的所有类添加正确的导入。
And, as @Gaurav Joseph mentioned, you are using wrong method to get file. 而且,正如@Gaurav Joseph所提到的,您正在使用错误的方法来获取文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.