File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Exceptions problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Exceptions problem" Watch "Exceptions problem" New topic

Exceptions problem

prerna boja
Ranch Hand

Joined: Aug 19, 2004
Posts: 67

I have the following program I get an error sayin Exception in "Main" .
Can anybody tell me where am I wrong.


public class RainFall
// Declare dataFile for input
private static BufferedReader dataFile;

static double getInches(BufferedReader dataFile, int numberDays)
throws IOException
// Reads and returns the total inches of rain
double total = 0.0;
double inches;
int days = 1;
while (days <= numberDays)
inches = Double.valueOf(dataFile.readLine()).doubleValue();
total = total + inches;
return total;

public static void main(String[] args) throws IOException
// Main is where execution starts. It opens the data file,
// reads the number of days of rain to be totaled, calls an
// auxiliary method to read and sum the rain fall, and prints
// the average rain fall on the screen
double totalRain;
int numDays;
double average;
// Instantiate and open the data file
dataFile = new BufferedReader(new FileReader(""));
// Input the number of days
numDays = Integer.valueOf(dataFile.readLine()).intValue();

totalRain = getInches(dataFile, numDays);

if (numDays == 0)
System.out.println("Average cannot be computed for 0 days.");
average = totalRain / numDays;
System.out.println("The average rainfall over " +
numDays + " days is " + average);
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Rather than simply throwing the exception from main, why not catch it and print it out? Do something like this:

That should give you more information to work with.

SCJP Tipline, etc.
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
I guess theres an exception occuring in the main function and since you are just throwing it but not catching it, your code is breaking somewhere and thus the exception is thrown. You have to catch it using the try catch block.

"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Here's what I get when I compile and run your program. What do you get?

C:\_Work\java>java RainFall
Exception in thread "main" (The system cannot find the file specified)
at Method)
at RainFall.main(

p.s. P*L*E*A*S*E use code tags next time (button labeled "CODE" next to the smilies).
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
prerna what is the exception? Can you please post the exact error message you get?


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Exceptions problem
It's not a secret anymore!