Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-29-2008, 06:54 PM
Member
 
Join Date: Sep 2008
Posts: 3
fiero is on a distinguished road
nullpointer exception in jsp
hi guys,
I am gettting org.apache.jasper.JasperException: java.lang.NullPointerException
I am using Hibernate in my appln to get data
pls help me;;;;;;;;;;;;;;;;;;;;;;;

here is the code::::::::

<%!
public void jspInit(ServletConfig config) {
try {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
} catch (HibernateException e) {
e.printStackTrace();
}//init(ServletConfig)
}

/*Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbcracle:thin :@path given:java","scott","tiger");
PreparedStatement ps=conn.prepareStatement("select distinct(job) from hb_emp");
ResultSet rs=ps.executeQuery();
while(rs.next())*/



Query query = session.createQuery("select eb.desg" + "from EmpBean eb");
Iterator it = query.iterate();
Boolean b = it.hasNext();
%>
<% while(b)
{ Object[] row = (Object[])it.next();

%>
<option value="<%=(String) row[0]%>"><%=(String) row[0]%></option>


<%}
%>

Last edited by fiero : 09-29-2008 at 08:21 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-29-2008, 07:37 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Without code, it's tough to see where an exception is thrown.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-29-2008, 10:51 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
I think it's in your while loop at the end of your code.

Code:
Boolean b = it.hasNext(); %> <% while(b) { Object[] row = (Object[])it.next(); %> <option value="<%=(String) row[0]%>"><%=(String) row[0]%></option> <%} %>
Boolean b is only being checked once, not after each iteration of the loop like you intended.

Try this:
Code:
%> <% while(it.hasNext()) { Object[] row = (Object[])it.next(); %> <option value="<%=(String) row[0]%>"><%=(String) row[0]%></option> <%} %>
Putting hasNext in the loop condition will make sure that it is checked each time through the loop.

I could be wrong though.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-29-2008, 10:53 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
I just looked at the API and noticed that Iterator's .next method throws a NoSuchElementException, not a NullPointerException so I might be wrong.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-01-2008, 10:30 PM
Senior Member
 
Join Date: Sep 2008
Posts: 131
georgemc is on a distinguished road
Just a pointer: scriptlets are A Bad Thing anyway, and anything, scriptlets or otherwise, that connects a JSP to a database, is a bad design. Try and layer the app a bit more, otherwise you'll be copying and pasting data access code all over the place
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-07-2008, 03:43 PM
Member
 
Join Date: Nov 2008
Posts: 5
Vijay Mishra is on a distinguished road
Send a message via Yahoo to Vijay Mishra
It may b prb of result giving null data, just try to make condition which checks null pointer
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-07-2008, 03:44 PM
Member
 
Join Date: Nov 2008
Posts: 5
Vijay Mishra is on a distinguished road
Send a message via Yahoo to Vijay Mishra
It may b prb of result giving null data, just try to make condition which checks null pointer then try it
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception rmaadil Database 1 05-19-2008 02:45 PM
Exception! rameshraj Advanced Java 1 05-05-2008 03:39 PM
Where does the exception go? aytidaalkuhs New To Java 3 04-07-2008 04:24 PM
Trouble with factory method - unhandled exception type Exception desmond5 New To Java 1 03-08-2008 08:41 PM
NullPointer Exception Preethi New To Java 8 02-06-2008 05:40 PM


All times are GMT +3. The time now is 06:33 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org