• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling another package function in Main function (selenium web driver)  RSS feed

 
tanvi manjrekar
Greenhorn
Posts: 2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all,


I have created a simple scripts .
in one package P1 with Main function and then calling other package class and its function in this main. but it giving me error of
Exception in thread "main" java.lang.NullPointerException

Please suggest how to resolve here are the line of codes from both scripts.
Script with Main ------




 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Please UseCodeTags (← that's a link) when you post code. I'll do it for you this time.

I don't see where you are instantiating driver, so it will be null and throw a NullPointerException.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also don't use coloured text or such long lines; I have corrected both for you.

And welcome again
 
Tim Harris
Ranch Hand
Posts: 57
3
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Null Pointer Exceptions occur when you are trying to access a resource that has not been assigned a value or initialized.

Where might this be the case in your code?

Hint: Just because you have declared a variable or object, does not mean it has been initialized or assigned a value.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by creating objects. Make the driver not static. Initialise it in the constructor. Move all that code out of the main method. Make the main method short. Very short.Everything else should be in other methods.
 
tanvi manjrekar
Greenhorn
Posts: 2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for editing post - really thankful of you guys.

As per the below solutions I have change my code line. I change method return type and access the driver object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!