TRY/CATCH ODDNESS

Discussion in 'Java' started by Obi Wan Shinobi, May 22, 2004.

  1. Hello people,

    Would someone please tell me why the following code (which I pretty
    much copied out word for word from Wrox' Beginning Java 1.4 book) is
    giving me a 'cannot resolve sybol error' referring to the first
    character inside the catch condition: (IOException e):

    public class AverageFruit {
    public static void main(String[] args) {
    double numOranges = 50.0E-1;
    double numApples = 1.0E1;
    double averageFruit = 0;

    averageFruit = (numOranges + numApples) / 2.0;
    System.out.println("A totlly fruity program");
    System.out.println("Average fruit is " + averageFruit);
    System.out.println("(Press Enter to exit)");

    try {
    System.in.read();

    } catch (IOException e) {
    return;
    }
    }
    }


    As you might have guessed i'm just starting out Java, so any help
    would be greatly appreciated.

    - Obi Wan
     
    Obi Wan Shinobi, May 22, 2004
    #1
    1. Advertising

  2. Obi Wan Shinobi

    Lee Weiner Guest

    In article <>, (Obi Wan Shinobi) wrote:
    >Hello people,
    >
    >Would someone please tell me why the following code (which I pretty
    >much copied out word for word from Wrox' Beginning Java 1.4 book) is
    >giving me a 'cannot resolve sybol error' referring to the first
    >character inside the catch condition: (IOException e):
    >
    >public class AverageFruit {
    > public static void main(String[] args) {
    > double numOranges = 50.0E-1;
    > double numApples = 1.0E1;
    > double averageFruit = 0;
    >
    > averageFruit = (numOranges + numApples) / 2.0;
    > System.out.println("A totlly fruity program");
    > System.out.println("Average fruit is " + averageFruit);
    > System.out.println("(Press Enter to exit)");
    >
    > try {
    > System.in.read();
    >
    > } catch (IOException e) {
    > return;
    > }
    >}
    >}

    Did you import the IOException class into your program?

    Lee Weiner
    lee AT leeweiner DOT org
     
    Lee Weiner, May 22, 2004
    #2
    1. Advertising

  3. Obi Wan Shinobi

    Sudsy Guest

    Obi Wan Shinobi wrote:
    <snip>
    > As you might have guessed i'm just starting out Java, so any help
    > would be greatly appreciated.
    >
    > - Obi Wan


    Use the force!
    Seriously, Lee gave you the answer. You must have this line at the
    top of the source file (after any package declaration):

    import java.io.IOException;

    Only java.lang is available by default.
     
    Sudsy, May 22, 2004
    #3
  4. That was it. Thanks :)
     
    Obi Wan Shinobi, May 23, 2004
    #4
  5. Obi Wan Shinobi

    Dave Guest

    In article <>,
    Sudsy <> wrote:

    >
    > Only java.lang is available by default.
    >


    Both java.lang and that crazy 'un-named' package (the package with no
    name) are available when you do not include a Package statement in your
    source code file...

    --Dave
     
    Dave, May 24, 2004
    #5
  6. Obi Wan Shinobi

    Roedy Green Guest

    On Mon, 24 May 2004 12:00:27 GMT, Dave <> wrote or quoted :

    >Both java.lang and that crazy 'un-named' package (the package with no
    >name) are available when you do not include a Package statement in your
    >source code file...


    avoid packageless classes except for toy experiments.

    They get into trouble with import.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 25, 2004
    #6
  7. Obi Wan Shinobi

    Dale King Guest

    Hello, Dave !
    You wrote:

    > In article <>,
    > Sudsy <> wrote:
    >
    > >
    > > Only java.lang is available by default.
    > >

    >
    > Both java.lang and that crazy 'un-named' package (the package

    with no
    > name) are available when you do not include a Package statement

    in your
    > source code file...


    That's a rather imprecise way of saying it. In reality it is that
    java.lang and the package that the source file is in are visible
    without qualifying the name.

    Leaving off the package statement means that the source file is
    in the unnamed packageso the unnamed package wouldbe accessible.
    --
    Dale King
    My Blog: http://daleking.homedns.org/Blog
     
    Dale King, Apr 15, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bienwell
    Replies:
    4
    Views:
    3,898
    bienwell
    May 27, 2005
  2. John Salerno
    Replies:
    20
    Views:
    881
    John Salerno
    Aug 11, 2006
  3. Fabio Z Tessitore

    who is simpler? try/except/else or try/except

    Fabio Z Tessitore, Aug 12, 2007, in forum: Python
    Replies:
    5
    Views:
    397
  4. =?Utf-8?B?QUo=?=

    When to TRY and not to TRY

    =?Utf-8?B?QUo=?=, Oct 16, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    345
    sloan
    Oct 17, 2007
  5. MRAB
    Replies:
    4
    Views:
    323
Loading...

Share This Page