Results 1 to 6 of 6
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default (newbie) String doesn't compile?!

    Not sure why, the following code doesn't compile:
    <code>
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package testone;

    /**
    *
    * @author User
    */
    import java.lang.*;
    import java.text.*;
    public class Main
    {
    public static void main(String[] args)
    {
    double x = 10000.0 / 3.0;
    NumberFormat formatter = NumberFormat.getNumberInstance();
    String s = formatter.format(x); // the string "3,333.33"
    System.out.println(s);

    }

    }
    </code>

    <error>
    init:
    deps-clean:
    Deleting directory C:\Documents and Settings\User\My Documents\NetBeansProjects\TestTwo\build
    clean:
    init:
    deps-jar:
    Created dir: C:\Documents and Settings\User\My Documents\NetBeansProjects\TestTwo\build\classes
    Compiling 1 source file to C:\Documents and Settings\User\My Documents\NetBeansProjects\TestTwo\build\classes
    C:\Documents and Settings\User\My Documents\NetBeansProjects\TestTwo\src\testtwo\Mai n.java:19: cannot find symbol
    symbol : class string
    location: class testtwo.Main
    public static void main(string[] args) {
    1 error
    BUILD FAILED (total time: 0 seconds)
    </error>

    Using NetBeans IDE 6.0
    Java SE 1.6

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    9

    Default

    Hi Jon, when you use code tags be sure to use the [ ]'s, not the < > :)

    I'm not so sure why this isn't compiling for you... I ran it and it compiles without a hitch. However, after looking at your error message, it appears you've changed the capitalization of the "String" which was lowercased "string" when you compiled- this will cause an error. Since you've capitalized, have you tried to compile your code again? Give it a shot.
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes that code compiled and run perfectly for me. As Captain says, the compiler can't find the symbol "string" and not compiled. Normally when you get such an error, look at what error message says. You can't figured the exact error each time. But it is not difficult at all.

    There in the error message you can find the line number is given, where the error is find. So it really help to find what the error is.

  4. #4
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Weird. Are you using Java 1.6?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  6. #6
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    9

    Default

    Jon, please post your new code if you've edited it in any way- heck, please post it anyways. I have a strong feeling you may have forgot that you edited your code before you posted it here. The compiler doesn't shoot out errors for no reason- the reason you posted there says "string" in lowercased, while your code is uppercase.. I really can't explain it easier than that. Please post your new code.
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

Similar Threads

  1. newbie needs help...
    By vicky08 in forum New To Java
    Replies: 2
    Last Post: 03-31-2008, 05:26 PM
  2. Newbie
    By CSnoob87 in forum Introductions
    Replies: 2
    Last Post: 02-18-2008, 09:49 AM
  3. Newbie in applet, Help me
    By barney in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 08:14 AM
  4. Help, java newbie
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 01:56 AM
  5. newbie: the app is loaded but i can't see it
    By tamayo in forum New To Java
    Replies: 1
    Last Post: 07-21-2007, 09:14 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
  •