This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Please use a thread title which makes it obvious what the question is about. "Variable might not have been initialized" would have been a better title. Then people reading the contents list can better choose which threads to reply to.
Please don't write "abt" or "alrite": look at this FAQ for an explanation.
Why are you declaring IOException from MeltPlot? If you really have to declare that Exception from the MeltPlot constructor, you will have to instantiate it like thisI think you have a design problem; you are opening a BufferedReader in the MeltPlot constructor; you ought to open the Reader when you need to read from the file, then close it again immediately. Make the reader a local variable of the method, not a field, nor a constructor local variable. You ought also to do the Exception handling in that method. It would read something like thisThe reason for the finally inside a try is to make sure the reader is definitely closed. Make sure there is only one statement inside such a finally; if you had two statements and teh first threw an Exception the second would never execute. Because the close() method declares IOException, the finally has to be inside a try. So you end up with a try with a try-finally inside.
You are obviously familiar with the ((line = something.readLine()) != null) syntax. You don't appear to be familiar with the methods of the Double class, however. There is a simpler way to get a double from a String.
Why are yuou declaring a StringBuffer (StringBulder would be better) in the constructor and never using it?
A small improvement over Campbell's code:
The creation of the Readers is already in a try-catch block, and it will only enter the nested try-finally block if the Readers have actually been opened. If it fails, it will skip that try-finally block so nothing is closed, but then again - nothing needs to be closed because nothing was opened.
As these examples show you, it's perfectly fine to nest try-catch-finally blocks. In fact, I prefer the following for copying data from one file to another:
Joined: Oct 13, 2005
Thank you, Rob. I never realised there was that enhancement. I bet I shall forget it before I next have to use it