Home > Archive > Java Help > October 2004 > cannot resolve symbol variable input (n00b question)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
cannot resolve symbol variable input (n00b question)
|
|
|
| Hi,
I keep gatting the "cannot resolve symbol variable input" even though
I think it has been initialised within the try block.
---------------------------------------------
public class MakeCircleEdit {
public static void main(String[] args) {
String inputnumber = JOptionPane.showInputDialog(null,"Wa'z yo
number bad boy?");
boolean is_numb_ok=false;
do{
try{
double input = Double.parseDouble(inputnumber); //if not number
then we go to the catch statement
is_numb_ok=true;
}
catch(NumberFormatException exp1){
inputnumber = JOptionPane.showInputDialog(null,"Eh rude boy, I
want a digit!");
}
}while(is_numb_ok!=true);
double degree = CircleEdit.radiansToDegrees(input); //ERROR
MESSAGE HERE
DecimalFormat f = new DecimalFormat("0.00"); //To format the
numbers.
CircleEdit c = new CircleEdit(input); //ERROR MESSAGE ALSO HERE
double circum = c.circumference();
double a = c.area();
JOptionPane.showMessageDialog(null,"\nThe degree value of the
radian is: " + f.format(degree) + " innit."+
"\nThe cirumference is: " + f.format(circum) + " innit."+
"\nThe area is: " + f.format(a) + " innit.");
}
}
---------------------------------------------
To make things more readible, here is my ealier version without the
error control, which works fine:
---------------------------------------------
public class MakeCircleEdit {
public static void main(String[] args) {
String inputnumber = JOptionPane.showInputDialog(null,"Wa'z yo
number bad boy?");
double input = Double.parseDouble(inputnumber);
double degree = CircleEdit.radiansToDegrees(input);
DecimalFormat f = new DecimalFormat("0.00"); //To format the
numbers.
CircleEdit c = new CircleEdit(input);
//c.r = input; //when not using constructor
double circum = c.circumference();
double a = c.area();
JOptionPane.showMessageDialog(null,"\nThe degree value of the
radian is: " + f.format(degree) + " innit."+
"\nThe cirumference is: " + f.format(circum) + " innit."+
"\nThe area is: " + f.format(a) + " innit.");
}
}
---------------------------------------------
I'm sure there is a blindingly obvious reason for it, please could you
help me ... :)
Thanks in advance,
Ess
PS: What is the peice of coding that closes the ms-dos window once the
program has reached the end?
| |
| Paul Lutus 2004-10-11, 4:01 pm |
| Ess wrote:
> Hi,
>
> I keep gatting the "cannot resolve symbol variable input" even though
> I think it has been initialised within the try block.
The problem is that you are declaring the "input" variable within a scope
that you then abandon, along with the variable.
Instead, declare "input" outside this specific control block, and assign it
as you are doing, but do not declare it at that location. e.g.:
double input;
// later on:
input = Double.parseDouble(inputnumber);
--
Paul Lutus
http://www.arachnoid.com
| |
| Madhur Ahuja 2004-10-12, 8:57 am |
| Paul Lutus <nospam@nosite.zzz> wrote:
> Ess wrote:
>
>
> The problem is that you are declaring the "input" variable within a
> scope that you then abandon, along with the variable.
>
> Instead, declare "input" outside this specific control block, and
> assign it as you are doing, but do not declare it at that location.
> e.g.:
>
> double input;
>
> // later on:
>
> input = Double.parseDouble(inputnumber);
Even this would give the error:
simple *input* might not have been initialized.
The correct would be:
double input =null;
try
{
input=.....
}
catch(Exception e)
{
....
}
--
Madhur Ahuja [madhur<underscore>ahuja<at>yahoo<dot>com]
Homepage
http://madhur.netfirms.com
| |
| Paul Lutus 2004-10-12, 3:59 pm |
| Madhur Ahuja wrote:
> Paul Lutus <nospam@nosite.zzz> wrote:
>
> Even this would give the error:
> simple *input* might not have been initialized.
Yes, because an assignment is not certain, I should have assigned a dummy
value to the variable to prevent this error.
>
> The correct would be:
>
> double input =null;
Really? Assigning null to a double primitive? I am not sure the word
"correct" should be applied to an example you didn't bother to compile.
In any case, thanks for pointing out my error.
--
Paul Lutus
http://www.arachnoid.com
| |
|
| Hi,
Thanks for helping, but my problem still remains ...
When I try this:
....
public class MakeCircleEdit {
public static void main(String[] args) {
String inputnumber = JOptionPane.showInputDialog(null,"Wa'z yo
number bad boy?");
double input=null;
boolean is_numb_ok=false;
do{
try{
input = Double.parseDouble(inputnumber); //if not number then we
go to the catch statement
is_numb_ok=true;
}
catch(NumberFormatException exp1){
inputnumber = JOptionPane.showInputDialog(null,"Eh rude boy, I
want a digit!");
}
}while(is_numb_ok != true);
double degree = CircleEdit.radiansToDegrees(input);
DecimalFormat f = new DecimalFormat("0.00"); //To format the
numbers.
....
I get the error:
MakeCircleEdit.java:12: incompatible types
found : <nulltype>
required: double
double input = null;
^
1 error
And when I try this way:
....
String inputnumber = JOptionPane.showInputDialog(null,"Wa'z yo
number bad boy?");
boolean is_numb_ok=false;
do{
double input=null;
try{
input = Double.parseDouble(inputnumber); //if not number then we
go to the catch statement
is_numb_ok=true;
}
catch(NumberFormatException exp1){
inputnumber = JOptionPane.showInputDialog(null,"Eh rude boy, I
want a digit!");
}
....
I get the error messages:
MakeCircleEdit.java:14: incompatible types
found : <nulltype>
required: double
double input=null;
^
MakeCircleEdit.java:27: cannot resolve symbol
symbol : variable input
location: class MakeCircleEdit
double degree = CircleEdit.radiansToDegrees(input);
^
MakeCircleEdit.java:30: cannot resolve symbol
symbol : variable input
location: class MakeCircleEdit
CircleEdit c = new CircleEdit(input);
^
3 errors
| |
| Paul Lutus 2004-10-13, 3:57 am |
| Ess wrote:
> Hi,
>
> Thanks for helping, but my problem still remains ...
>
> When I try this:
>
> ...
>
> public class MakeCircleEdit {
>
> public static void main(String[] args) {
>
> String inputnumber = JOptionPane.showInputDialog(null,"Wa'z yo
> number bad boy?");
>
> double input=null;
No, this was a mistake by another poster. It should be:
double input = 0;
Didn't you read my post that replied to his?
--
Paul Lutus
http://www.arachnoid.com
| |
|
| > No, this was a mistake by another poster. It should be:
>
> double input = 0;
>
> Didn't you read my post that replied to his?
Sorry, your second to last post wasn't posted here before I made my last post.
Thanks for your help guys, got the program working. :)
|
|
|
|
|