aspose file tools*
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
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: 10289
    
168

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);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null Pointer Exception