'I cannot figure out Uncompilable source code - variable might not have been initialized
I'm new to learning Java and am writing a BMI Calculator program. I've fixed so many errors in my program but just cannot figure this one out! Hopefully, you can help and it will be the last error I need to fix so it will finally execute without errors.
Then I can make some changes for it to do exactly what I want such as exception handling to deal with incorrect values entered etc.
I've spent so much time on this and have edited it so much that I have got myself so confused. All feedback welcome, I'm here to learn.
This is the error I am getting on Netbeans:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable bmi might not have been initialized at BmiCalc.main(BmiCalc.java:9)
Here is my code:
{
double bmi;
if (bmi < 18.5) {
System.out.println("You are underweight");
}
else if (bmi >= 18.5 && bmi <= 24.9) {
System.out.println("You are a healthy, normal weight");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|