Results 1 to 4 of 4

Thread: GUI IOException

  1. #1
    serfster is offline Member
    Join Date
    Jun 2008
    Posts
    8
    Rep Power
    0

    Default 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?
    Last edited by serfster; 06-13-2008 at 02:59 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    serfster is offline Member
    Join Date
    Jun 2008
    Posts
    8
    Rep Power
    0

    Default

    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.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    create a try / catch similar to this:
    Java 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?

Similar Threads

  1. Replies: 3
    Last Post: 04-10-2008, 09:01 AM
  2. java.io.IOException: invalid header field
    By osval in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 11:09 PM
  3. Variable passing, Error: IOException
    By fernando in forum New To Java
    Replies: 3
    Last Post: 07-31-2007, 02:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •