ActionListener

private class InputButtonListener implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

String rainString, wheatPriceString, barleyPriceString, sorghumPriceString;

double rain, wheatPrice, barleyPrice, sorghumPrice;

convert(enterRainfall, rainString, rain);

convert(enterWheatPrice, wheatPriceString, wheatPrice);

convert(enterBarleyPrice, barleyPriceString, barleyPrice);

convert(enterSorghumPrice, sorghumPriceString, sorghumPrice);

}

private void convert(JTextField textField, String string, double value)

{

string = textField.getText();

value = Double.parseDouble(string);

}

}

}

I am getting an error saying : variable rainString might not have been initialised. Anyone have any ideas on what I can do? aside from declaring the strings and doubles at the beginning of the entire class

[922 byte] By [hornetsfan16a] at [2007-11-27 5:29:31]
# 1

When you post code, please use[code] and [/code] tags as described in [url=http://forum.java.sun.com/help.jspa?sec=formatting ]Formatting tips[/url] on the message entry page. It makes it much easier to read.

Where do you set rainString to equal something in your code?

I don't think Convert is doing what you think it is doing.

Read the following:

http://www.javaranch.com/campfire/StoryCups.jsp

http://www.javaranch.com/campfire/StoryPassBy.jsp

Message was edited by:

mlk

mlka at 2007-7-12 14:52:49 > top of Java-index,Java Essentials,New To Java...
# 2
initialise them with an empty String or null.String rainString="", wheatPriceString="", barleyPriceString="", sorghumPriceString="";
PhHeina at 2007-7-12 14:52:49 > top of Java-index,Java Essentials,New To Java...
# 3

This would work:

String rainString = "", wheatPriceString = "", barleyPriceString = "", sorghumPriceString = "";

double rain = 0.0, wheatPrice = 0.0, barleyPrice = 0.0, sorghumPrice = 0.0;

But my question is, what do you intend to do with these fields later? They are not accessable in their present form. Do you have getters and setters?

petes1234a at 2007-7-12 14:52:49 > top of Java-index,Java Essentials,New To Java...
# 4
ok thanks i'll do that (initialise them as null) though how come when I normally declare a string or a double at the beginning of a class I don't have to initialise it
hornetsfan16a at 2007-7-12 14:52:49 > top of Java-index,Java Essentials,New To Java...
# 5
i'm just trying to get this to store the values in those variables, but yes I will have getters
hornetsfan16a at 2007-7-12 14:52:49 > top of Java-index,Java Essentials,New To Java...
# 6
> i'm just trying to get this to store the values in> those variables, but yes I will have gettersThe method "Convert" is not doing what you think it is doing, read the second link I posted above.
mlka at 2007-7-12 14:52:49 > top of Java-index,Java Essentials,New To Java...