-
GUI IOException
I am trying my make a GUI app that reads from a random access file. I get an error message saying that the method can't throw an IOException and that "its invocation must be enclosed in a try statement that catches the exception, or else this method must be declared to throw the exception", so since I need to run this code and there is nothing that seems to actually be wrong with it, I added "throws IOException" to the method where all of the code for my GUI app is written, but I cannot add "throws IOException" to the run() method that runs the GUI because it is not "assignable". If I use a try and catch on my random access file code that supposedly yields an IOException, the code is not executed since an "IOException" is caught. How do I get Java to run this code?
-
If I were you, the big question that I would try to answer is: why is an IOException being thrown when you try to access the file? You're doing something wrong, and hopefully the stack trace will tell you what it is. Fix that, and then your try/catch block should work. If still having trouble, you may want to post a *small* compilable program that illustrates your problem.
-
I am just starting to learn Java and I do not know what "stack trace" is? I am sorry. Please have patience for my lack of knowledge. Thanks.
-
create a try / catch similar to this:
Code:
try
{
// do your file IO here
}
catch (IOException e)
{
e.printStackTrace();
}
and then read what the e.printStackTrace outputs. It should give you insights as to what's going wrong. You may not be looking for your file in the right place or reading it wrong.
Question: why the use of random access file here? Why not just a plain text file?