File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local variable g is not initilized

 
numan ahmad
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
numan ahmad
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the value of g if s > 20000 or s < 4000?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic