views:

41

answers:

2
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!

A: 

From your code it's not clear, what the In class is. Also you're accessing the tallene array which is neither declared nor initialized in your code. Maybe a

tallene = new char[type*type];

before the for loop could solve your problem. For a better answer, we would need more details (especially what kind of 'crash' you're experiencing ...)

MartinStettner
Its the String filnavn=chooser.getName(); In innfil=new In(filnavn);when I try to set the name of the file as the new in, regardless of the file being in my java-dir, it crashes.
Richards
A: 

Doh, sorry to bother you. Im too tired.

I went straight from the filechooser without setting a File=chooser.getSelectedfile();

sorry :O

Richards