Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null Pointer Exception

 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get NullPointerException while running the following program.
This program works perfectly in Tomcat 6.0.
Why should it fail in JBOSS?
If I use "Class.ForName(...)", I am able to access the database.

The list I got after running, http://localhost:8080/jmx-console, jndi View :

JBoss
JMX MBean Operation Result list()
Back to Agent View Back to MBean View Reinvoke MBean Operation

Web Applications


My web-xml has :
<resource-ref>
<res-ref-name>jdbc/PostgresDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

My jboss-web.xml has :
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/PostgresDS</res-ref-name>
<jndi-name>jdbc/PostgresDS</jndi-name>
</resource-ref>
</jboss-web>
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are having a NullpointerException because the datasource is not injected (if not, post the exception stacktrace). Which version of JBoss are you using? Injection in servlets is not supported in JBoss version 4.2.x or prior versions. It's supported starting JBoss 5. See this for an explanation.
 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jaikiran.

I use 4.2.2GA.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you stepped through it in the debugger?
did that provide any insight?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic