Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Why am I getting a java.lang.NullPointerException ?

 
Ranch Hand
Posts: 873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi expert,

I have this method which worked long ago but now I am getting a java.lang.NullPointerException.

Hope someone can point out the mistake to me.  Tks.



I have doubled checked that the sql statement is correct....in sql it is SELECT * FROM projectSchemaName.items

 
Sheriff
Posts: 8266
592
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please post a stack trace? It contains useful information about the failing reason.
 
tangara goh
Ranch Hand
Posts: 873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Could you please post a stack trace? It contains useful information about the failing reason.



Here it is but here is no cause of reason being mentioned...

 
Marshal
Posts: 3824
537
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:Here it is but here is no cause of reason being mentioned...




Where is statement being initialized?
 
tangara goh
Ranch Hand
Posts: 873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

tangara goh wrote:Here it is but here is no cause of reason being mentioned...




Where is statement being initialized?



I had declared a private Static Statement statement....
 
Ron McLeod
Marshal
Posts: 3824
537
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:I had declared a private Static Statement statement....


Ok - but where is it initialized?
 
lowercase baba
Posts: 13048
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You say you declared it.  But that simply means you've told java "i'm going to have a thing called 'statement', and it will be of <whatever> type".

but if you've not initialized it, you've not actually created the object it refers to.  somewhere, you'd need to have a line like



 
Saloon Keeper
Posts: 9252
78
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A Statement must be created from a Connection. You should be doing that in your openConnection() method. You can't re-use a Statement from a prior open Connection.
 
tangara goh
Ranch Hand
Posts: 873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all.  Really appreciate it.  Thank you so much.  It is working now.
 
tangara goh
Ranch Hand
Posts: 873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

A Statement must be created from a Connection. You should be doing that in your openConnection() method. You can't re-use a Statement from a prior open Connection.



You are on the dot of the problem!
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic