*
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
Author

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))
g=1;
else if((s>=8000 && s<=10000))
g=2;
else if((s>=5000 && s<=8000))
g=3;
else if ((s>=4000 && s<=5000))
g=4;

return g;


}

public int getText( char g){

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

else if(g==3)
t=.05;

else if(g==4)
t=.02;

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
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

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
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

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: ]
 
 
subject: local variable g is not initilized
 
Similar Threads
A Special TextEdit control for Date
NumberFormatException : null
Program Output not working
Error coming 500 please an code is
Here is the source code for a fully DateDocument