This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSP and the fly likes local variable g is not initilized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSP
Bookmark "local variable g is not initilized " Watch "local variable g is not initilized " New topic

local variable g is not initilized

numan ahmad
Ranch Hand

Joined: Jan 27, 2011
Posts: 49
hay every one i am new in java programing and need your help..
i make a form in HTML page and want to transfer data on jsp page but its giving me an error that "local variable g in method getGrage() is not initialized" please help me friends.i shall be very thankful to you and thanks in advance ..
here is my code

public int getGrade(int s){

int g ;
if ((s>=10000) && (s<=20000))
else if((s>=8000 && s<=10000))
else if((s>=5000 && s<=8000))
else if ((s>=4000 && s<=5000))

return g;


public int getText( char g){

double t;
if (g==1)
else if(g==2)

else if(g==3)

else if(g==4)

return t;


int Salary =Integer.parseInt(request.getParameter("s"));
int Allowance =Integer.parseInt(request.getParameter("a"));
int PF =Integer.parseInt(request.getParameter("p"));
int GrosSalary=Allowance+Salary;

int grad=getGrade(Salary);

double persentage=getText(grad);

double text=Salary*persentage;
double netDeduction=text+PF;

double TotalSalary=GrosSalary-netDeduction;
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63211

If you are new to Java and JSP you should know right off the bat that putting Java code into JSP is bad bad practice that has been discredited for almost ten years now.

You should develop good habits right off the bat and never put Java code into new JSPs. Lear the JSTL and EL which are the moderne says to use JSP.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
numan ahmad
Ranch Hand

Joined: Jan 27, 2011
Posts: 49
my class teacher teach me like that and i am doing as they teach me...
sorry i did not get your point??? i watched lot of tutorials on youtube and every one use definition tag to write java function...
Rob Spoor

Joined: Oct 27, 2005
Posts: 20078

What will be the value of g if s > 20000 or s < 4000?

How To Ask Questions How To Answer Questions
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63211

If you have to write things this way for school.... well, good gravy, tell your instructor that you hope he's going to update the course to moderne standards. :rolleyes:

The error message means that you are using g before it has been given a value. Check the code to make sure that g is initialized before its first use.

And please be more careful when posting. Your post is full of typos and inaccuracies. That may cause people to just look for someone one else to help who will take more care in posting.

[Edit: ah, Rob snuck in before me! :cool: ]
I agree. Here's the link:
subject: local variable g is not initilized
It's not a secret anymore!