• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer exception when class is called through interface

 
Ashmitha Vishwam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34214
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first example, where do you call the set method?
 
Ashmitha Vishwam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The setter is not called anywhere.. It was accidentaly selected along with other variables while generating setters and getters.
 
Swastik Dey
Rancher
Posts: 1603
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first case where is this.remoteFacade is getting initialized?
 
Ashmitha Vishwam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All required beans are initialized in the initContext() method of the test class in this way ..
 
Swastik Dey
Rancher
Posts: 1603
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1603
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you do this

 
Ashmitha Vishwam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic