Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting null pointer exception in Struts

843840Aug 28 2008 — edited Aug 28 2008
Getting null pointer exception plz help

Stack Trace
javax.servlet.ServletException
	org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	sun.reflect.GeneratedMethodAccessor242.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:585)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:239)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:266)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:157)


root cause 

java.lang.NullPointerException
	com.news.Article.execute(Article.java:49)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	sun.reflect.GeneratedMethodAccessor242.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:585)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:239)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:266)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:157)
this is class
//select *from article where id='check'*
*package com.news;*
*import org.apache.struts.action.*;
import java.util.*;*
*import java.sql.*;
import javax.sql.DataSource;
import java.io.*;*
*import javax.servlet.*;
import javax.servlet.http.*;
import com.news.utility.DispBean;

public class Article extends Action
{
	private Connection con=null;
	private DataSource dataSource=null;
public ActionForward execute(ActionMapping mapping, ActionForm aform, HttpServletRequest request, HttpServletResponse res) 
	throws ServletException, IOException
	{
	HttpSession session=request.getSession();
		ServletContext context=session.getServletContext();
	DynaActionForm form= (DynaActionForm)aform;
	Object article_id=form.get("article_id");
	List l= new ArrayList();

		DispBean temp= new DispBean();
		try{
		con=com.news.utility.Util.getConnection();
		Statement st=con.createStatement();
		st.executeUpdate("update article set seen=seen+1 where id='"+article_id+"'");
		ResultSet rs=st.executeQuery("select * from article where id='"+article_id+"'");
		ResultSetMetaData rsmd= rs.getMetaData();
		if(rs.next())
		{

			for(int i=0;i<rsmd.getColumnCount();i++)
			{
				temp.set(rsmd.getColumnName(i+1),rs.getObject(i+1));
			}	

		}
		else{ return mapping.findForward("norecord");}
		rs.close();
		st.close();
		//con.close();
		}catch(Exception e){//context.log(e.getMessage(),e);
		com.news.utility.Util.sendMail(e,con);}
		try{con.close();}catch(java.sql.SQLException e){}
		session.setAttribute("article",temp);
		//session.setAttribute("others",l);

	return mapping.findForward("success");
	}
}
Struts-config.xml
<action path="/article" name="ArticleActionForm" type="com.news.Article" validate="false">
		<forward name="success" path="/article.jsp"/>
		<forward name="norecord" path="/norecord.jsp"/>
		<forward name="error" path="/error/dberror.html"/>
		</action>
check online
[http://www.ispattimes.com/article.do;jsessionid=D3D11F502805543D8A43C322CCC649C4?article_id=11|Ispattimes.com]
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 25 2008
Added on Aug 28 2008
1 comment
1,072 views