nus-cs2103-AY2223S2 / forum

12 stars 0 forks source link

Saving error when exporting iP to jar file #47

Closed Tempura-Person closed 1 year ago

Tempura-Person commented 1 year ago

image

as suggested by the instructions below, i exported my iP into a jar file using intelliJ's build artifacts function. The whole thing functions properly besides the 'bye' command (which does not terminate the process) and the autosave feature failing to work (as i set up an error message to display if it happens)

image

These bugs seem to be exclusive to the exported jar file (the project still works fine within intelliJ) and i don't know how to fix them properly.

Tempura-Person commented 1 year ago

for some context: image how 'bye' works is that all user input is handled by the Parser class.

The Parser class has a loopEnd boolean that signals when the 'bye' command has been entered, before updating it to true.

image

At the end of every command of user input, the main method (in the Duke class) updates to be the same as loopEnd in the Parser class, so when loopEnd in Parser is true, the loop to accept user input also stops in the main method.

Tempura-Person commented 1 year ago

as for the autosave, it is also handled by Parser automatically every time a command is handled. image

image

i assume the error is because the filepath "data/duke.txt" cannot be accessed, but isn't this already a relative filepath?

hansstanley commented 1 year ago

Check if you have handled the case where the folder doesn't exist, as the .jar file likely won't have a /data folder in the directory it is situated.

From the module website:

Your code must handle the case where the data file doesn't exist at the start. Reason: when someone else takes your Duke and runs it for the first time, the required file might not exist in their computer. Similarly, if you expect the data file to be in as specific folder (e.g., ./data/), you must also handle the folder-does-not-exist-yet case.

SPWwj commented 1 year ago

try 1.check if directory exist if not mkdir 2.check if file exist if not create files

do allow to print the original exception msg as it will give you more info during debugging. hope this can help :)

Tempura-Person commented 1 year ago

that did it, i didnt check if the file and directory existed first time around, now it works in .bat autotesting and the exported .jar file. Thanks!

lhy-hoyin commented 1 year ago

Hello! It appears that your issue have been resolved :D Perhaps @Tempura-Person can mark this issue as Close as completed. Thank you! (But it you think your question is still not answered, perhaps you can reiterate what you would like to clarify.)

nus-se-bot commented 1 year ago

@Tempura-Person A gentle reminder to close this issue if the problem has been resolved. If not resolved yet, please post a comment explaining which part of the problem/question remains unresolved.

nus-se-bot commented 1 year ago

@Tempura-Person I'm closing this issue due to inactivity. Feel free to reopen if the issue is still unresolved.