File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes The local variable may not have been initialized. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "The local variable may not have been initialized." Watch "The local variable may not have been initialized." New topic
Author

The local variable may not have been initialized.

Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 418
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

Joined: Jan 28, 2008
Posts: 5575

local variable must be initialized before it's use.
Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 418
Hello,

I tried this, and it did not work:



Do you have any suggestions?

Thanks, Michele
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Apr 20, 2008
Posts: 7
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The local variable may not have been initialized.