Java bean gives null pointerexception

Posted on 2003-11-01
Last Modified: 2010-04-01
   I know this is really very very funny.At times my java bean application works and at times it give an exception of null pointer.
I think my problem is that maybe i am not using the get  properly,

I mean, when i use set i use:

<jsp:useBean id="vol" class="com.dhal.volun" scope="session"/>
<jsp:setProperty name="vol" property="*"/>

But i use the getters such as:

Do i need to write something maybe to use it, for example,


coz, when i look at work folder for the jas_jsp files it seems as if vol is null.

But if write
username gets printed so i am surprise which is null.

Question by:Jasbir21
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 14

Expert Comment

ID: 9664825
the is nothing wrong of the code that u have posted. the problem is in somewhere else, post the full stack trace of you exception.

Author Comment

ID: 9664907

When  i looked at the line 250,it is about this line

The java code for query that i use is....

   connection = DriverManager.getConnection(connectionURL, "", "");
   String myquery="select * from account where username='Jasbir22'";

   String query="select * from volunteer where username='Jasbir22'";

    .......//its is alot here


   catch(SQLException ex ) {  ex.printStackTrace() ; }

   catch( ClassNotFoundException ex ){  ex.printStackTrace() ; }


LVL 14

Accepted Solution

kennethxu earned 60 total points
ID: 9665009
rs.getString(2) is giving you null.

make sure password is the column number 2 and it is not null for user Jasbir22.
BTW, I'd suggest you to use column name instead of possition, since position might change if you add new columns to database.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9665059
   I don't understand something, does it mean that a column value cannot be null because if its it would give a null pointer,
sometimes, a user would need not enter a column, soit is null


Author Comment

ID: 9665154
when i type describle table,

i get

So, i guess it is at column 2 ????

How do i do it the column name way

LVL 15

Assisted Solution

dualsoul earned 40 total points
ID: 9665270
>So, i guess it is at column 2 ????
columns are counted from ResultSet, not DB schema, but in your it's the same, because you retrive all columns.

>How do i do it the column name way
just use overloading methods in ResultSet:
    String s=rs.getString("password");


Author Comment

ID: 9665607
When you say column are counted from Resultset,

how are they are counted...

LVL 14

Expert Comment

ID: 9665838
>> When you say column are counted from Resultset.
that's the order in your select statment. it's same if you use select *, but if you use select password, username from..., then the order is password, username.

>> does it mean that a column value cannot be null
NO, the problem is that you are doing a trim(), so if the rs.getString() returns null, you are doing s = null.trim(), of course, you get NPE.
for those columns that could be null in database, you should always use
String s = rs.getString("columnname");
if( s != null ) s=s.trim();

Author Comment

ID: 9667239
......I have been spending days to find out what my problem, and you guys in experts - exchange solved in seconds.Thank you so much....


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Primefaces: How to display a variable that can take only 'Y' or 'N' or a boolean value. 2 128
Fisheye tool 2 125
Can't access image with tomcat/html 6 114
throw exception 21 78
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
Invest in your employees with these five simple steps to improve employee engagement and retention.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question