[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

Variable might not have been initialized ????

Hey experts,
I get this error "Variable userInp might not have been initialized"  to the below code:

                        answer = Calculator(userInp, op1 , op2) + answer.substring(indexR + 1);

does anyone knows why im getting this error ??

0
perdoname_
Asked:
perdoname_
1 Solution
 
sciuriwareCommented:
answer and indexR    should have some value before you can get a substring or index the substring.

What's the rest of the code prior to this one?

;JOOP!
0
 
Ajay-SinghCommented:
In Java, all the local variables should be initialized before you can use
them.
0
 
ronghaoCommented:
try initializing the variable,
if it's a  String:  String userInp = "";
if it's a int: int userInp = 0;
if it's a double: double userInp = 0.0;

hope these helps.. :)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now