2

Beginner Java learner here. Yesterday, the compiler was telling me that it "cannot find symbol" for Double.parseDouble(). The only "solution" I have right now to circumvent this "error" is to use import java.lang.Double. I never created any classes named Double or Integer, either. Can someone help me understand why the compiler is throwing this error and how to rectify it?

Sample code:

import java.util.Scanner;

public class doubleparse
{
    public static void main(String[] args) 
    {
        double number;

        Scanner in = new Scanner(System.in);

        System.out.print("Enter a number: ");
        String input = in.nextLine();
        number = Double.parseDouble(input);
    }
}

Error:

doubleparse.java:13: error: cannot find symbol
number = Double.parseDouble(input);
               ^
symbol:   method parseDouble(String)
location: class Double
1 error

Why does the compiler throw this message every time I use a parsing method? I've seen it throw this when I use the Integer.parseInteger() method too.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • 1
    What is `class.parseClass()`? I don't see that in your code. What is the actual full error message you get? – Max Vollmer Jul 21 '18 at 19:12
  • 1
    `The only "solution" I have right now to circumvent this "error" is to use "import java.lang.Double"` In Java, you have to import these classes. That's normal behavior – ByteHamster Jul 21 '18 at 19:28
  • 1
    Do you have your own `Double` and `Integer` classes in the project? – Max Vollmer Jul 21 '18 at 19:29
  • If you haven't already, you can read [this post](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) on "Cannot find symbol" errors in Java. – 0xCursor Jul 21 '18 at 19:29
  • 5
    @ByteHamster That is incorrect. `java.lang.*` is implicitly imported. – Max Vollmer Jul 21 '18 at 19:30
  • @ByteHamster I understand but I never have to to such import when I started learning Java. –  Jul 21 '18 at 19:31
  • @MaxVollmer I never created any classes named Double or Integer. Is that usually the reason why this error happens? –  Jul 21 '18 at 19:32
  • 1
    The error you get sounds like Java takes the wrong `Double` and `Integer` classes from somewhere. It would be good to know more about your project and Java version. – Max Vollmer Jul 21 '18 at 19:32
  • 1
    Especially because it says `class Double` and not `class java.lang.Double`, which sounds like it finds a class with that name in the default package. – Max Vollmer Jul 21 '18 at 19:34
  • @MaxVollmer Okay. Shall I look for any project that shares the same Integer or Double in its class name then? –  Jul 21 '18 at 19:37
  • @mchlvncntry No problem. – 0xCursor Jul 21 '18 at 19:38

0 Answers0