加载文件并获取其内容对我来说崩溃了
private class Lytterklasse implements ActionListener{
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"Sudoku Tekstfiler", "txt");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(getParent());
String filnavn=chooser.getName();
In innfil=new In(filnavn);
int type=innfil.inInt();
int lengdeBoks=innfil.inInt();
int breddeBoks=innfil.inInt();
for(int i=0;i<type*type;i++){
tallene[i]=innfil.nextChar();
}
}
}
为什么这会让我崩溃?我想不通。请帮忙!
private class Lytterklasse implements ActionListener{
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"Sudoku Tekstfiler", "txt");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(getParent());
String filnavn=chooser.getName();
In innfil=new In(filnavn);
int type=innfil.inInt();
int lengdeBoks=innfil.inInt();
int breddeBoks=innfil.inInt();
for(int i=0;i<type*type;i++){
tallene[i]=innfil.nextChar();
}
}
}
Why does this crash on me? I cant figure it out. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的代码中不清楚
In
类是什么。此外,您还访问了tallene
数组,该数组既没有在代码中声明也没有初始化。也许在
for
循环之前可以解决您的问题。为了获得更好的答案,我们需要更多详细信息(尤其是您正在经历什么样的“崩溃”......)From your code it's not clear, what the
In
class is. Also you're accessing thetallene
array which is neither declared nor initialized in your code. Maybe abefore the
for
loop could solve your problem. For a better answer, we would need more details (especially what kind of 'crash' you're experiencing ...)呵呵,抱歉打扰你了。我太累了。
我直接从文件选择器进入,没有设置 File=chooser.getSelectedfile();
抱歉:O
Doh, sorry to bother you. Im too tired.
I went straight from the filechooser without setting a File=chooser.getSelectedfile();
sorry :O