Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following code & it gives the null pointer exception on line no.62 action=request.getParameter("ACTION")& i'm not getting it
so can somebody help me through this.............
Thanx.......

XML
<%@page import="java.util.ArrayList"%>
<%@page import="Ptech.Updation_Deletion"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String user_id = (String)session.getAttribute("SID");
    int id = Integer.parseInt(user_id);
    String Name="";
    String UserName="";
    String Password="";
    String From_Date="";
    String To_Date="";
    String Card_ID="";
    String status="";
    String company_name=(String)session.getAttribute("company_name");
    String branch_name=(String)session.getAttribute("Branch_Name");
    Updation_Deletion updel = new Updation_Deletion();
    ArrayList al = new ArrayList();
    al=updel.userUpdate_Delete(id);
    if(!al.isEmpty())
               {
        //id=Integer.parseInt(al.get(0));
        Name=(String)al.get(1);
        UserName=(String)al.get(2);
        Password=(String)al.get(3);
        From_Date=(String)al.get(4);
        To_Date=(String)al.get(5);
        Card_ID=(String)al.get(6);
        status=(String)al.get(7);
        System.out.println("UID"+id);
            }


%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form action="For Updation_Deletion.jsp" method="post">
        <table border="1" width="200">
            <tr><td>Name:</td><td><input type="text" name="NAME" value="<%=Name%>"/></td></tr>
            <tr><td>UserName:</td><td><input type="text" name="USERNAME" value="<%=UserName%>"/></td></tr>
            <tr><td>Password:</td><td><input type="text" name="PASSWORD" value="<%=Password%>"/></td></tr>
            <tr><td>From_Date:</td><td><input type="text" name="FROM_DATE" value="<%=From_Date%>"/></td></tr>
            <tr><td>To_Date:</td><td><input type="text" name="TO_DATE" value="<%=To_Date%>"/></td></tr>
            <tr><td>Card_ID:</td><td><input type="text" name="CARD_ID" value="<%=Card_ID%>"/></td></tr>
            <tr><td>Status:</td><td><input type="text" name="STATUS" value="<%=status%>"/></td></tr>
            <tr><td>Company_Name:</td><td><input type="text" name="COMPANY_NAME" value="<%=company_name%>"/></td></tr>
            <tr><td>Branch_Name:</td><td><input type="text" name="BRANCH_NAME" value="<%=branch_name%>"/></td></tr>
        </table>
            <input type="submit" name="ACTION" value="Edit"/>
            <input type="submit" name="ACTION" value="Delete"/>
            <input type="button" name="BACK" value="Back"/>
            <%
            String action ="";
            if(!action.equals(null))
                               {
      action= request.getParameter("ACTION");
        if (action.equals("Edit")) {
                session.setAttribute("Tr_Flag", "U");
                System.out.println("IF");
            } else if (action.equals("Delete")) {
                session.setAttribute("Tr_Flag", "D");
            } else {
                session.setAttribute("Tr_Flag", "I");
            }
           }
            %>
        </form>
    </body>
</html>
Posted
Updated 21-Aug-13 20:08pm
v2
Comments
Thanks7872 22-Aug-13 1:55am    
Am i suppose to find line no.62?
_Asif_ 22-Aug-13 1:58am    
seems like session object has not been appropriately created and initialized and is null therefore raising null pointer exception when you involved setAttribute method. Check why session is null
pasztorpisti 22-Aug-13 5:50am    
Instead of action.equals("Edit") use "Edit".equals(action), this way it isn't a problem if the action variable contains null. In case of comparing with constant strings its always better to call the method of the constant because we know that the constant isn't null and the equals() method deals well with a null parameter.

Looks like you mixed up varaibles in the if clause the line above.
Since you initialize action to an empty string , it is never null. Consequently, checking for action being null - if(!action.equals(null)) - does not make sense. I suspect you wanted to check for request being null.
By the way, where is request initialized?
 
Share this answer
 
Both the input field has same name :
HTML
<input type="submit" name="ACTION" value="Edit"/>
           <input type="submit" name="ACTION" value="Delete"/>


Try with different name for each input
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900