Results 1 to 4 of 4
  1. #1
    Pacha is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default Constant Expression Required

    Can anyone tell me what's wrong with the following code. I get the error "constant expression required" at the case statement but the following is from my book example. Thanks!
    import java.io.*;

    class StreamTokenizerDemo2 {


    public static void main(String[] args) {
    try {
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    StreamTokenizer st = new StreamTokenizer(br);
    st.whitespaceChars(',', ',');

    while(st.nextToken() != StreamTokenizer.TT_EOF) {
    switch(st.ttype) {
    case st.TT_WORD:
    System.out.println(st.lineno() + ") " + st.sval);
    break;
    case st.TT_NUMBER:
    System.out.println(st.lineno() + ") " + st.nval);
    break;
    default:
    System.out.println(st.lineno() + ") " + (char) st.ttype);
    } }
    fr.close();
    }

    catch(Exception e) {
    System.out.println("Exception: " + e);
    }


    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,304
    Rep Power
    20

    Default Re: Constant Expression Required

    Pacha

    Do you really think this is an advanced topic? There's a New to Java section for questions like these.

    Anyhow, since you chose to ask the question here, the answer can be found in Chapter*14.*Blocks and Statements read with the two topics linked from that section:
    Chapter*15.*Expressions
    Chapter*8.*Classes

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,304
    Rep Power
    20

    Default Re: Constant Expression Required

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Pacha is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default Re: Constant Expression Required

    Sorry, I'm new to this and I just chose any topic and it seems advanced to me. :)

    Thanks for your help.

    Quote Originally Posted by DarrylBurke View Post
    Pacha

    Do you really think this is an advanced topic? There's a New to Java section for questions like these.

    Anyhow, since you chose to ask the question here, the answer can be found in Chapter*14.*Blocks and Statements read with the two topics linked from that section:
    Chapter*15.*Expressions
    Chapter*8.*Classes

    db

Similar Threads

  1. constant in object ??
    By dojob in forum New To Java
    Replies: 6
    Last Post: 09-17-2013, 08:02 PM
  2. Cannot use as static constant
    By KiranA in forum Eclipse
    Replies: 1
    Last Post: 12-01-2011, 09:19 AM
  3. Replies: 2
    Last Post: 07-18-2011, 07:11 AM
  4. Constant Variables
    By harshakantha in forum New To Java
    Replies: 3
    Last Post: 06-13-2011, 07:51 AM
  5. switch() don't work with constant
    By jarek in forum Advanced Java
    Replies: 3
    Last Post: 11-19-2010, 08:59 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
  •