Results 1 to 10 of 10

Thread: '}'' expected

  1. #1
    bezdaniel is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default '}'' expected

    private static final int MAX_bks = 3;
    bkcollection[] collection = new bkcollection[MAX_bks];
    public void saveRecords(){
    {try
    {
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(Book));
    out.writeObject(collection);
    out.close();
    }
    catch (Exception ioe)}
    }

    This is a 'save' array for a basic program in Java of a Library.
    The only error I have however is that after the ')' after 'Exception ioe' in:

    "catch (Exception ioe)}"

    the program says that there is a syntax and a "'{' expected".

    I am very new to Java and any help is appreciated.
    Thanks.

  2. #2
    jbarke12's Avatar
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    88
    Rep Power
    0

    Default Re: '}'' expected

    You have an unmatched {. If i had to guess it would be the one before the try that you need to get rid of.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: '}'' expected

    Nice, first question on the forum and already under attack by a troll.

    @original poster: try formatting the code nicely so all the accolades match up to each other, you'll see where the booboo is.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: '}'' expected

    Please place your code between code tags so it is properly formatted.

    The error is telling you that the curly braces, {}, don't match up and since it is expecting '}' you either have too many open braces '{' or they are improperly positioned. In your case it is the latter. Get rid of the one before the try and put one after the closing parenthesis after the catch.

    Regards,
    Jim
    Last edited by jim829; 10-29-2013 at 06:45 PM. Reason: removed reference to deleted post
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: '}'' expected

    Quote Originally Posted by jim829 View Post
    Second, ignore the moron in the earlier post.
    Oi!

    Alright I'll give you that one.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: '}'' expected

    Lol! The post was deleted and you intercepted the comment. I deleted the statement.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: '}'' expected

    I love sowing confusion like that...:)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: '}'' expected

    Quote Originally Posted by Tolls View Post
    I love sowing confusion like that...:)
    You forgot to dump him in the machine with the rotating knives; I did it for you. He is an ex-user now, he is no more.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    bezdaniel is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default Re: '}'' expected

    Thanks for you kind help people.
    However, I edited the program like this:

    private static final int MAX_bks = 3;
    bkcollection[] collection = new bkcollection[MAX_bks];
    public void saveRecords(){
    try
    {
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(Book));
    out.writeObject(collection);
    out.close();
    }
    catch (Exception ioe)
    }

    and now it the error I'm receiving is '{' expected. Sorry about the bother again.. but can anyone identify the problem please?
    Thanks once again.

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: '}'' expected

    The problem is with your try/catch construct. Look at it closely. Both the try and the catch must have a block associated with them.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. ')' and '(' expected
    By Bindlz in forum New To Java
    Replies: 4
    Last Post: 04-06-2011, 01:51 AM
  2. '{' expected
    By elliojonhy in forum New To Java
    Replies: 3
    Last Post: 12-01-2010, 10:26 PM
  3. ';' expected
    By lala in forum New To Java
    Replies: 2
    Last Post: 11-24-2010, 09:02 PM

Tags for this Thread

Posting Permissions

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