JSP AND BEAN PROBLEmjava.lang.nullpointerexceptionhelp me please

hello i have a problem, when i open login.jsp and enter the form i have nullpointerexception. i don't understand where i wrong... i use tomcat 5.5 ... sorry for my english i'm italian and i speak only italian :(

login.jspthis is the code of the java server page

<html>

<%@ page language="java" import="java.sql.*" %>

<jsp:useBean id="lavoro" scope="page" class="Ok.Dino"/>

<%@ page session="false" %>

<style type="text/css">

<!--

body{

background-color: #003366;

}

a:link{

color: #CCCCCC;

}

.style1{

color: #000000;

font-weight: bold;

font-size: x-large;

}

.style4{font-size: 18px}

-->

</style>

<body>

<%if(request.getMethod()=="GET"){

%>

<form action="login.jsp" method="POST" name="frmlogin" id="frmlogin">

<div align="center">

<p class="style1">AUTENTICAZIONE

<table width="318" height="140" border="1">

<tr>

<td width="95" height="60" bordercolor="#000000" bgcolor="#0066CC"><p align="center"><strong>USER</strong>

</td>

<td width="207" bgcolor="#0099CC"><p align="center">

<input type="text" name="txtnome">

</td>

</tr>

<tr>

<td height="72" bordercolor="#000000" bgcolor="#0066CC"><strong>PASSWORD</strong> </td>

<td width="207" bgcolor="#0099CC"><div align="center">

<input name="pwdtxt" type="password">

</div></td>

</tr>

</table>

<table width="318" border="1">

<tr>

<td width="318" height="87"> <div align="center">

<input name="submit" type="submit" value="invia" >

</div>

<p align="center"><strong><span class="style4">Se non sei registrato fallo <a href="file:///C|/Documents and Settings/access/Documenti/My Received Files/registrazione.jsp">adesso </a></span></strong>

</td>

</tr>

</table>

</div>

</form>

<%}else{ %>

<%lavoro.settxtnome(request.getParameter("txtnome"));%>

<%!ResultSet rs=null;

String x=null;

%>

<% lavoro.cn_db("dbutenti");%>

<% rs=lavoro.run_query("SELECT user FROM utenti");%>

<%}%>

</body>

</html>

and this is the bean code

package Ok;

import java.sql.*;

publicclass Dino

{

private String txtnome,pwdtxt;

private Connection cn=null;

private Statement st=null;

private ResultSet Rs=null;

public String gettxtnome()

{

return txtnome;

}

public String getpwdtxt()

{

return pwdtxt;

}

publicvoid settxtnome(String n)

{

this.txtnome=n;

}

publicvoid setpwdtxt(String n)

{

this.pwdtxt=n;

}

publicvoid cn_db(String db)

{

if(cn==null){

//1. Caricamento del driver

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}catch(ClassNotFoundException cnfe){

System.out.println("impossibile caricare il driver");

System.exit(1);

}

try{

//2. Connessione al DB

cn = DriverManager.getConnection("jdbc:odbc:"+db);

//3. creazione degli oggetti Statement e ResultSet

st =cn.createStatement();

}catch(SQLException e){

System.out.println(e+"jjj");

}

}else{

System.out.print("errore database gi脿 creato");

}

}

public ResultSet run_query(String qr)

{

try{

Rs=st.executeQuery(qr);

}catch(SQLException e)

{

System.out.print(e+"ecco l'error");

}

return Rs;

}

}

[7894 byte] By [accessroota] at [2007-11-27 6:15:35]
# 1

Do you understand when a NullPointerException will be thrown? This will be thrown if you want to access an uninstantiated Object.

So look to the stacktrace and go to the line where the NPE is been thrown and doublecheck if the object reference is actually instantiated.

Or add a null-check to the object reference:if (someObject != null) {

someObject.doSomething();

}

or just instantiate it:if (someObject == null) {

someObject = new SomeObject();

}

someObject.doSomething();

BalusCa at 2007-7-12 17:26:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
the NPE is here<% rs=lavoro.run_query("SELECT user FROM utenti");%>i understund your solution but the query shouldn't be null because the database isn't empty.thanks for your answer however
accessroota at 2007-7-12 17:26:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
i have tomcat 5.5 maybe have not set up it well as one does
accessroota at 2007-7-12 17:26:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
hi,can u remove this method in ur code and see hw it is working// if(request.getMethod()=="GET"){
sudhinaa at 2007-7-12 17:26:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...