• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to slove nullpointerexception

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i hardly trying to read xls file i getting null pointer Exception please guide me please see below code

String imp=request.getParameter("F1");
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

//Below line i getting java.lang.NullPointerException

conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+imp);

st = conn.createStatement();
String query = "Select * from [Sheet1$]" ;
rs = st.executeQuery( query );
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+imp);


I'd be suprised if you could get a NullPointerException on this line. Is it really the line where the exception occurs?
 
saravanan rajendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thanks for yr reply. yes i getting exception that line only before that line i given display statements its all printing but after that line no display statement working

//here i getting parameter value
String imp=request.getParameter("F1");
out.println(imp);//its displaying that value

Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
out.println("welcome");//this one displaying

//Below line i getting java.lang.NullPointerException

conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ="+imp);//
out.println("welcome2");//this line not printing

st = conn.createStatement();
String query = "Select * from [Sheet1$]" ;
rs = st.executeQuery( query );
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, the NullPointerException will tell you the line number and the class this is happening in. The line you say it is happening on can't cause a NullPointerException itself, since it is a static methos you are calling. So it must be something else. Can you post the stacktrace?
 
saravanan rajendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thanks for your guide. when i compiling that code not showing any error.when i calling that file in web browser up to that line all print statement displaying after that line no display statement working i thinking that line only having problem please see Below code i trying to get and read xls file.please guide me i trying lot

code:
try
{
//getting parameter value
input of F1="C:/asia/book1.xls"
String imp=request.getParameter("F1");

out.println("welcome5");//printing
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

out.println("welcome to peopletech23999884");//printing
out.println(imp);printing C:/asia/book1.xls

//after imp value printed its printing java.lang.NullPointerException

conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + imp);
out.println("welcome to peopletech1");//not printing here onwards no print statement displaying

st = conn.createStatement();
String query = "Select * from [Sheet1$]" ;
rs = st.executeQuery( query );
while( rs.next() )
{
String name=rs.getString(1);
String loc=rs.getString(2);
try
{

Class.forName
("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "meetme", "meetme");
st = conn.createStatement();
st.executeUpdate("Insert INTO sample1(`name` , `location`)VALUES('"+ name +"' ,'"+ loc +"')");
rs1=st.executeQuery("select * from sample1");
if(rs1.next())
{
out.println(name);
}
}
catch(Exception e)
{
out.println(e);
}
}//while
}//try
catch( Exception e )
{
out.println(e);
}
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


when i compiling that code not showing any error


A NullPointerException is a runtime exception. You'll only see it when you run the code.


catch( Exception e )
{
out.println(e);
}



Can you change thsi line to:


rerun your applciation and post the out put. As I said before, NullPointerExceptions tell you the class and line that they are occuring on. The line you say this is happening on is a call to a static method, so its not the line that is causing the problem (though another problem may be occuring when you call it). Post the stacktrace and we can help more.
 
saravanan rajendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, thanks for your guide. now null pointer exception not showing but after that line no print statement displaying.what the value i read that also not stored in database please guide me
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by saravanan rajendran:
hi, thanks for your guide. now null pointer exception not showing but after that line no print statement displaying.what the value i read that also not stored in database please guide me



Not showing? Is nothing appearing in your logs?
 
saravanan rajendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thank you, up to that line what are the print statement i given its displaying after that line no print statement displaying but its not showing null pointer exception also please guide me
 
saravanan rajendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friend i eagerly waiting for you reply. After that line no other code executing directly coming to that catch statement and its came out from program.please guide me
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so you must have done somethign to where stderr is logged. Which servlet container are you using? If its Tomcat, and a pre-version 6 version, stderr goes to the stderr.log, not localhost.log. Check your log files. It will be fr easier to fix this if we have some proper exception messages.
 
saravanan rajendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, thanks for your reply, In my log file does not contain stderr.log file

It contain
host-manager.log
manger.log
local host-manager.log
catalina.log
admin.log

those file only contain please guide me
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I'd check how you've set up your logging (see this). No sense trying to fix this blindly in the dark. Get the stacktrace then we can do something to fix it.

Also, does the file C:/asia/book1.xls exist on the server?
 
saravanan rajendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, thank you very much for your reply.yes i have C:/asia/book1.xls exist in my server.but i don't know about stderr.log file how to get and put that please guide me
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"stderr" isn't usually a log file. It is shorthand for the standard error stream which is represented by a java.io.PrintStream object usually called java.lang.System.err. You are doubtless familiar with it as System.err; it is similar to System.out.
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic