This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JBoss/WildFly and the fly likes Null Pointer Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Null Pointer Exception" Watch "Null Pointer Exception" New topic
Author

Null Pointer Exception

Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
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

Joined: Jul 20, 2005
Posts: 9947
    
160

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.


[My Blog] [JavaRanch Journal]
Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
Thanks, Jaikiran.

I use 4.2.2GA.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
have you stepped through it in the debugger?
did that provide any insight?


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
 
Don't get me started about those stupid light bulbs.
 
subject: Null Pointer Exception
 
Similar Threads
netbeans 5.5 + Jboss 4.0.4 + EJB 3.0
Problem deploying sample HelloWorld Bean in JBoss 4.2.1 GA
EJB application deployment problem
Problem with this example
Stateful Bean Naming Exception