This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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: 15042

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: 24195

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!