Closed tayxuenye closed 1 day ago
@tayxuenye can you share the jar file, so others can try it too?
Ok im not sure if this is definitely the issue but:
File directory = new File("data");
File file = new File(filePath);
if (!directory.exists()) {
directory.mkdir();
}
if (!file.exists()) {
file.createNewFile();
ui.showToUser("Created new data file optimus.txt");
return taskList;
}
In your main class u already defined the filepath already and then here u are defining it differently here to check if it exists. So maybe, there is some bug which causes duplicated files (notice that the directory is defined separately before the file when in filepath it comes together) causing your storage class to be confused when it needs to create its own file. So it might be the reason why u are facing it outside of ur repo (because u need to create it there).
I would suggest changing the above code to the following:
File f = new File(filepath);
f.getParentFile().mkdirs();
f.createNewFile();
f.exists();
hopefully it works for you!
@tayxuenye can you share the jar file, so others can try it too?
@tayxuenye can you share the jar file, so others can try it too?
Prof, unfortunately github does not support sending jar files
Hi I'm also getting this issue. I'm using a Macbook and it seems that this problem only occurs when trying to run from the jar file. If I do the ./gradlew run
on the IntelliJ terminal, it works fine and I can read the previous safe file. But if I do ./gradlew clean shadowJar
and go to the directory and run the following, I get the error message:
My input in the terminal
java -jar Winde.jar
The error message I get
Error in creating fileNo such file or directory
Error Loading Tasks to File: ../src/main/java/windebot/Winde.java (No such file or directory)
Prof, unfortunately github does not support sending jar files
@tayxuenye you can either zip it up first and attach it to a post here, or create a release in GitHub and upload the jar file to the release.
../src/main/java/windebot/Winde.java
@WinstonJin
.java
file?The simplest relative path you can use is something like Winde.txt
(which expects the file to be in the same folder as the jar file). Of course if the file is missing, your code needs to create it first.
Oh my bad prof, I copied the wrong error code for this
Error in creating fileNo such file or directory
Error Loading Tasks to File: ../src/main/java/windebot/WindeTasks.txt (No such file or directory)
So I tried changing the file path to WindeTasks.txt
instead of the ../src/main/java/windebot/WindeTasks.txt
and I get a long error message:
Caused by: java.lang.NullPointerException: Cannot invoke "java.io.File.mkdirs()" because the return value of "java.io.File.getParentFile()" is null
at windebot.History.load(History.java:60)
at windebot.Winde.<init>(Winde.java:40)
at gui.Main.<init>(Main.java:17)
... 11 more
This is the line 60 code in History:
if (!file.exists()) {
file.createNewFile();
file.getParentFile().mkdirs(); // line 60
file.createNewFile();
// file.exists();
@WinstonJin let's not hijack this issue to discuss your case. Can you open another issue for it?
Ok im not sure if this is definitely the issue but:
File directory = new File("data"); File file = new File(filePath); if (!directory.exists()) { directory.mkdir(); } if (!file.exists()) { file.createNewFile(); ui.showToUser("Created new data file optimus.txt"); return taskList; }
In your main class u already defined the filepath already and then here u are defining it differently here to check if it exists. So maybe, there is some bug which causes duplicated files (notice that the directory is defined separately before the file when in filepath it comes together) causing your storage class to be confused when it needs to create its own file. So it might be the reason why u are facing it outside of ur repo (because u need to create it there).
I would suggest changing the above code to the following:
File f = new File(filepath); f.getParentFile().mkdirs(); f.createNewFile(); f.exists();
hopefully it works for you!
Ok im not sure if this is definitely the issue but:
File directory = new File("data"); File file = new File(filePath); if (!directory.exists()) { directory.mkdir(); } if (!file.exists()) { file.createNewFile(); ui.showToUser("Created new data file optimus.txt"); return taskList; }
In your main class u already defined the filepath already and then here u are defining it differently here to check if it exists. So maybe, there is some bug which causes duplicated files (notice that the directory is defined separately before the file when in filepath it comes together) causing your storage class to be confused when it needs to create its own file. So it might be the reason why u are facing it outside of ur repo (because u need to create it there).
I would suggest changing the above code to the following:
File f = new File(filepath); f.getParentFile().mkdirs(); f.createNewFile(); f.exists();
hopefully it works for you!
Seems to run ok now. Thank you so much!
When I copied and pasted my jar file to downloads, the app runs but is unable to load file. Does anyone have an idea why? The file path passed in is data/optimus.txt . It works fine when in the original iP directory.