Results 1 to 7 of 7
  1. #1
    aserothbw is offline Member
    Join Date
    Aug 2009
    Posts
    9
    Rep Power
    0

    Default exception error in a ActionListener class

    I am having an issue with one of the GUIs I am currently working on. The GUI itself works fine, but the actionlistener tied to it, keeps coming up with exception errors.

    The listener is used to create an instance of a seperate class that connects to, accesses, and returns data from a database. All of the database functions are kept within the class, and all its exceptions are handled, etc. However, when I try to code the listener on the gui side, I keep getting compile errors asking for the exceptions being handled in the db class to be added to the actionlistener. If I add them, I get more compiler errors stating that they are not compatible with actionlistener.actionperformed. Can anyone shed some light on this problem?

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    The default workaround would seem to be the blunderbuss approach:
    Java Code:
    [INDENT]try {
    ...
    } catch (Exception ex) { ex.printStackTrace(); }[/INDENT]
    This should get the code to compile, but needs something more user friendly in the catch-body.

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    actionPerformed is not allowed to throw checked exceptions. Either handle them or better yet, separate your DB access code from your interface code.
    You should certainly not be trying to connect to a database on the EDT.

  4. #4
    programmer_007's Avatar
    programmer_007 is offline Senior Member
    Join Date
    Aug 2009
    Posts
    125
    Rep Power
    0

    Default

    Better make separate functions for particular data access .... and call them in actionPerformed...

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by programmer_007 View Post
    Better make separate functions for particular data access .... and call them in actionPerformed...
    That would be a no-op (no operation) because
    1.) Those separate functions still need to handle the exceptions anyway and
    2.) Those functions called from actionPerformed would be called on the EDT and asking the EDT to do database stuff is serious disrespect.

  6. #6
    aserothbw is offline Member
    Join Date
    Aug 2009
    Posts
    9
    Rep Power
    0

    Default

    thank you all for the input. It turns out that I had an extra throw clause in my db code that was causing the compiler error to pop up. Once the throw clause was deleted, Everything ran fine. It's always the simple things that cause the biggest problems. . .

  7. #7
    programmer_007's Avatar
    programmer_007 is offline Senior Member
    Join Date
    Aug 2009
    Posts
    125
    Rep Power
    0

Similar Threads

  1. Exception error
    By Rose88 in forum New To Java
    Replies: 8
    Last Post: 07-06-2009, 10:22 PM
  2. Exception error
    By jaiminparikh in forum New To Java
    Replies: 0
    Last Post: 03-20-2009, 09:06 PM
  3. ActionListener Error
    By blackstormattack in forum New To Java
    Replies: 1
    Last Post: 03-05-2009, 08:36 AM
  4. Exception Error need help fixing
    By skinnybones in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 07:14 PM
  5. JSF error+exception
    By Peter in forum SWT / JFace
    Replies: 1
    Last Post: 07-04-2007, 06:29 AM

Posting Permissions

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