0

i am trying to work in JFileChooser To get File selected from another class i don't care how the button look like but when some one click on it. it should show JFileChooser to select srt file (like text file but another type) and it should read it.

this is my first class

    package AnimeAid;
import java.io.*;
import javax.swing.*;

public class ReadFile {
    private File ourFile= null;
    private static final JFileChooser selectSrtFile = new JFileChooser();
    String filePath = "";

       public ReadFile(){

       }

    public File getSelectFile(){ 
            selectSrtFile.setFileSelectionMode(JFileChooser.FILES_ONLY);
            selectSrtFile.showSaveDialog(null);
            ourFile = selectSrtFile.getSelectedFile();
            filePath = ourFile.getAbsolutePath();
            return ourFile;
    }

        public String readFileInput(){
            try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(getSelectFile()), "UTF-8"));
              String line;
                while ((line = reader.readLine()) != null)
                {
                    System.out.println(line);
                }
            }catch(IOException ex){
            return "there is wrong";
            }
            return "file is added";

        }

}

the scanned class

    package AnimeAid;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


/**
 *
 * @author isslam
 */
public class GuiInterface extends JFrame {

    JTable table;
    JButton is;
    ReadFile t;

    public GuiInterface(String title){
    setSize(900, 700);
    setTitle(title);
    setDefaultCloseOperation(GuiInterface.EXIT_ON_CLOSE);
    is = new JButton();
    t = new ReadFile();
    Container cp = getContentPane();
    cp.add(is);

    is.addActionListener(new addButtonWatcher());

    }



    private class addButtonWatcher implements ActionListener{

         @Override
         public void actionPerformed(ActionEvent a){
             Object buttonPressed=a.getSource();
             if(buttonPressed.equals(is))
             {
              t.getSelectFile(); 
             }
}
    }
}

the error message

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: animeaid.GuiInterface
    at animeaid.main.main(main.java:15)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
isslam akkilah
  • 418
  • 1
  • 11
  • 23
  • It looks like you're using NetBeans, so you might have run into the same issues as described in these questions: http://stackoverflow.com/questions/20165965/java-runtimeexception-uncompilable-source-code-erroneous-tree-type and http://stackoverflow.com/questions/2333285/java-lang-runtimeexception-uncompilable-source-code-what-can-cause-this . The answers to those questions suggest turning off "Compile on Save", which may not fix your problem but the compiler may then show you the actual error in your code. – andersschuller Jan 14 '14 at 21:56
  • i did turn it off i give me another error but i think no need to turn it off just click on clean and build but still i need help with this issue – isslam akkilah Jan 14 '14 at 22:09
  • does the other class pass you the filename, or are you wondering how to use JFileChooser to get the filename (then read the file)? – rogerdpack Jan 14 '14 at 22:15
  • in the scanned class guiInterface i was trying to tell run the method from the first class ReadFile to tell java to one JFileChooser and to select file then read it there is wrong with my code – isslam akkilah Jan 14 '14 at 22:22
  • Clean and build you code again... – MadProgrammer Jan 14 '14 at 22:40
  • ok i did with out the compile on save i posted the error message – isslam akkilah Jan 14 '14 at 22:51

1 Answers1

1

It looks like your two classes have different packages:

package animeFactor;
             ^

and

package animefactor;
             ^

I believe Java package names are case sensitive, so despite the fact that you have (probably) put the two files in the same folder, the GuiInterface class cannot use the ReadFile class without importing it.

Either change the package definitions to be the same, or add an import statement to GuiInterface:

import animeFactor.ReadFile;
andersschuller
  • 13,509
  • 2
  • 42
  • 33