Results 1 to 4 of 4
  1. #1
    israelyan is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Advice needed on DecimalFormat class

    Hello,

    I ran into an error compiling a very simple Java program. Please consider the code below:
    import java.text.DecimalFormat;
    class DecimalFormat {
    public static void main(String[] args) {
    double d = 2.123456;
    DecimalFormat df = new DecimalFormat("#O.OO");
    System.out.println(df.format(d));
    }
    }

    And the error message:
    DecimalFormat.java:1: DecimalFormat is already defined in this compilation unit
    import java.text.DecimalFormat;
    ^
    DecimalFormat.java:6: cannot find symbol
    symbol : constructor DecimalFormat(java.lang.String)
    location: class DecimalFormat
    DecimalFormat df = new DecimalFormat("#O.OO");
    ^
    DecimalFormat.java:8: cannot find symbol
    symbol : method format(double)
    location: class DecimalFormat
    System.out.println(df.format(d));
    ^
    3 errors


    Can you explain what the problem is?
    I'm using version javac 1.6.0_20 of the Java compiler on Linux.

    Thanks,
    Sam

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Have you created a class yourself called DecimalFormat that is being used instead of the class in the standard Java library?

  3. #3
    israelyan is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    Thanks for the hint! After I read your post, I realised that the class I created has the same name as the built-in one. I was blind :)

    Thanks!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by israelyan View Post
    Thanks for the hint! After I read your post, I realised that the class I created has the same name as the built-in one. I was blind :)
    You're welcome. Per Oscar Wilde: Experience is the name every one gives to their mistakes. I'm very "experienced". :)

Similar Threads

  1. Advice needed :)
    By kagster in forum New To Java
    Replies: 1
    Last Post: 11-16-2010, 01:04 AM
  2. general advice needed
    By mac in forum New To Java
    Replies: 1
    Last Post: 03-18-2010, 03:25 PM
  3. Advice needed
    By dineshjf in forum Advanced Java
    Replies: 18
    Last Post: 01-09-2009, 03:17 AM
  4. DecimalFormat class
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 12-30-2007, 03:09 PM
  5. Prerequisite advice needed
    By Hatrabbit in forum New To Java
    Replies: 2
    Last Post: 11-30-2007, 04:38 PM

Posting Permissions

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