aspose file tools*
The moose likes Testing and the fly likes Null pointer exception when class is called through interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Null pointer exception when class is called through interface" Watch "Null pointer exception when class is called through interface" New topic
Author

Null pointer exception when class is called through interface

Ashmitha Vishwam
Greenhorn

Joined: May 05, 2010
Posts: 7
Hi,
The project that i am writing junits for has a few classes where the they call the methods in a different class through an Interface like this ..


The problem is that, on encountering the code ftpStatus = this.remoteFacade.handleFTPLogin(userName, password);, a null pointer is thrown. But if i call the class directly, no exceptions are thrown. All beans are initialized in the init method.



Could someone tell me what might be causing this?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30758
    
156

In the first example, where do you call the set method?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ashmitha Vishwam
Greenhorn

Joined: May 05, 2010
Posts: 7
The setter is not called anywhere.. It was accidentaly selected along with other variables while generating setters and getters.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

In the first case where is this.remoteFacade is getting initialized?


Swastik
Ashmitha Vishwam
Greenhorn

Joined: May 05, 2010
Posts: 7
All required beans are initialized in the initContext() method of the test class in this way ..
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

I am not talking about the beans, I am talking about the remoteFacade reference. What happens if you modify the code like tihs


Ashmitha Vishwam
Greenhorn

Joined: May 05, 2010
Posts: 7
It is null. All variables are null. How can i initialise them in the test class so that they are available for the entire test?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

What happens if you do this

Ashmitha Vishwam
Greenhorn

Joined: May 05, 2010
Posts: 7
I see what you mean. Anyway i'll do those in my test class method so that i dont have to alter my original code. I have altered it this way.



I thought that initializing them with ApplicationContext did this job for me. Looks like i was wrong.

Also i find that putting this just once in the setUp() method of the test class is enough.

Thanks a lot for your time Swastik.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null pointer exception when class is called through interface