• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The local variable may not have been initialized.

 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I am trying to run a test page. Below is my code.

On encryptedQueryString; and final String decryptedQueryString;

I am receiving the errors: The local variable may not have been initialized. Can anyone help me figure this out? -- Thanks, Michele

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
local variable must be initialized before it's use.
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I tried this, and it did not work:



Do you have any suggestions?

Thanks, Michele
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hints:
1) what ever you put between <% %> , it goes inside service method.

2) if you create a class inside <% %> , then it is a local inner class.

 
Mahesh G P
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simple below code reports 'The local variable str may not have been initalized even though I do a Null check.

String str;
try {
str = new String("Hello");
}
finally {
if (str != null)
System.out.println(str);
}

My query is "If variable is not initiazlied won't it be null"?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahesh G P wrote:My query is "If variable is not initiazlied won't it be null"?

even the declaration wont be in .class file . i.e compiler removes String str; if str doesnt have assigment further lines.
So, checking str have further assignment logic in compiler may be not smart enough to prevent error that you get now ;)

<edit>*context is about local variable</edit>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have Java code in your JSP? That's a poor and obsolete practice from over 10 years ago. See this JspFaq entry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic