File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Not being able to compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Not being able to compile" Watch "Not being able to compile" New topic

Not being able to compile

Tontang Bei
Ranch Hand

Joined: Oct 21, 2006
Posts: 130
class q16{
public static void main(String[] args){
String Str="1.1";
double doubleVal;

catch(Exception e){}
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

Next time, please explain what the error message is that you get instead of just posting the code without any comments at all.

You're probably getting an error message that says the variable doubleVal may not have been initialized.

Look at your code. What happens when Double.parseDouble(Str) throws an exception? Execution goes to the catch block, but the variable doubleVal remains uninitialized. In Java, you must initialize local variables before you refer to them (as you do in the System.out.println(...) statement at the bottom.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Tontang Bei
Ranch Hand

Joined: Oct 21, 2006
Posts: 130
Sorry but even when I initialize I am getting error. cannot find symbol
symbol : method parseDouble(java.lang.String)
location: class Double
1 error

Am I using method incorrectly?
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
If I change this line:

double doubleVal = 0.0;

your program works fine for me. Have you ever been able to compile any programs?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Tontang --

I bet you've written a class named "Double" at some point, and your file "Double.class" is still hanging around somewhere. Delete it, and try not to name your own classes the same as common Java API class names!

[Jess in Action][AskingGoodQuestions]
Tontang Bei
Ranch Hand

Joined: Oct 21, 2006
Posts: 130
Thankyou Mr. Hill. You are a Genius!!
I agree. Here's the link:
subject: Not being able to compile
It's not a secret anymore!