Hi,
I have an issue trying to read a file. Iam getting a file not found ex, but the file seems to be there.
This is my project
This the code that is loading the file.
Java Code:
public GATEApplication(String appPath) {
try {
loadGATEApplication(appPath);
corpus = Factory.newCorpus("mainCorpus");
application.setCorpus(corpus);
} catch (GateException e) {
e.printStackTrace();
}
}
/**
* Loads the .gapp file to GATE
*
* @param path the .gapp file path
*/
private void loadGATEApplication(String path) {
try {
Gate.init(); // must run first before any GATE API calls can be made.
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(path).getFile());
System.out.println(file.getPath()); // the path is correct
application = (CorpusController) PersistenceManager
.loadObjectFromFile(file); // exception thrown here
} catch (GateException | IOException e) {
e.printStackTrace();
}
}
I test the constructor like this:
Java Code:
public static void main(String[] args) {
GATEApplication g = new GATEApplication("GATE applications/film_paum.gapp");
//File file = new File("ML_Model/GATE applications");
//for(String fileNames : file.list()) System.out.println(fileNames);
the stack trace
Java Code:
java.io.FileNotFoundException: C:\Users\Overlord\workspace\Sentiment%20Analysis%20ML%20App\bin\GATE%20applications\film_paum.gapp (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.http://ift.tt/QSp0th(Unknown Source)
at sun.net.http://ift.tt/1iey6X5(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at gate.util.persistence.PersistenceManager.isXmlApplicationFile(PersistenceManager.java:1013)
at gate.util.persistence.PersistenceManager.loadObjectFromUrl(PersistenceManager.java:857)
at gate.util.persistence.PersistenceManager.loadObjectFromFile(PersistenceManager.java:831)
at gate_resources.GATEApplication.loadGATEApplication(GATEApplication.java:87)
at gate_resources.GATEApplication.<init>(GATEApplication.java:67)
at gate_resources.Test.main(Test.java:8)
Exception in thread "main" java.lang.NullPointerException
at gate_resources.GATEApplication.<init>(GATEApplication.java:69)
at gate_resources.Test.main(Test.java:8)
but the path on the exception is correct and the file is there. I don't see why this is happening.
No comments:
Post a Comment