-2

I get an IOException error when trying to compile this code:

public class TextEditor extends JDialog implements ActionListener  {

    public TextEditor (File fich,Frame owner) throws IOException{
    super(owner,true);
    fichier=fich;
    String langage="//fortran_regex";
    cree_ihm(langage);
    };  

    public String config( String langage ) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader (langage));
    String         line = null;
    StringBuilder  stringBuilder = new StringBuilder();
    String         ls = System.getProperty("line.separator");

    try {
    while( ( line = reader.readLine() ) != null ) {
        stringBuilder.append( line );
        stringBuilder.append( ls );
    }

    return stringBuilder.toString();

    } finally {
    reader.close();
    }
    }   

    private void cree_ihm(String langage) throws IOException{
        config(langage);
    }
}

///////When calling main

import utils.TextEditor;

public class launch_editeur {
    public static void main(String[] args) throws IOException{
        TextEditor editeur=new TextEditor(null); 
        editeur.Affiche(true);
        //editeur.setControlOn(false);
    }
}

What is happening? Am I using it wrongly? I think it may have to do with the functions I called (or maybe with the classes? ) Thx

L4c0573
  • 333
  • 1
  • 7
  • 23
Carlos
  • 109
  • 5
  • 2
    You're getting this error when you compile it? – ControlAltDel Feb 11 '16 at 14:16
  • I get this: launch_editeur.java:5: error: cannot find symbol public static void main(String[] args) throws IOException{ ^ symbol: class IOException location: class launch_editeur 1 error – Carlos Feb 11 '16 at 14:40

2 Answers2

3

From your comment:

I get this: launch_editeur.java:5: error: cannot find symbol public static void main(String[] args) throws IOException{ ^ symbol: class IOException location: class launch_editeur 1 error

That's not the same as an IOException error (which happens at runtime), that's a compile error saying it can't find the class IOException. You need to import the IOException in the classes that use it:

import java.io.IOException;
user812786
  • 4,302
  • 5
  • 38
  • 50
0

The reader.close() call in your finally block needs a try { } catch around it, as it also can throw an IOException

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80