Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Greenhorn
Posts: 2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ------




 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 74085
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also don't use coloured text or such long lines; I have corrected both for you.

And welcome again
 
Ranch Hand
Posts: 57
3
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 74085
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic