How to handle null point exception while using switch strings

Was able to launch and close browser 1 only.

      at java.util.Hashtable.put(Unknown Source)
      at java.util.Properties.setProperty(Unknown Source)
      at java.lang.System.setProperty(Unknown Source)
      at newpackage.Launchbrowsers.Browser(
      at newpackage.Launchbrowsers.main(

Thanks in advance for any help.
newbie javaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You'll need to post some code if you want more help on this.
You don't really handle an NPE. That exception is an indication of an error in programming. You need to determine why you have null strings for properties and take action accordingly
newbie javaAuthor Commented:
package newpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Launchbrowsers {

      public static void main(String[] args)throws Exception {
      public static void Browser(String Launcher) {
            case "Chrome":
                  String file1 = System.getProperty("user.dir")+"/lib/chromedriver.exe";
                  WebDriver driver1 = new ChromeDriver();
                  System.out.println("Chrome is successfully launched and closed");
            case "IE":
                  String file2 = System.getProperty("C:/Users/newproject/lib/IEDriverServer.exe");
                  System.setProperty("", file2);
                  WebDriver driver2 = new InternetExplorerDriver();
                  System.out.println("InternetExplorer is successfully launched and closed");
            case "Firefox":
                  String file3 = System.getProperty("user.dir")+"/lib/geckodriver.exe";
                  WebDriver driver3 = new FirefoxDriver();
                  System.out.println("Firefox is successfully launched and closed");
                  System.out.println("Errors in browser + driver configuration");
I thought I had attached the .java file here. Sorry, here's the program I'm trying to execute.
I think your problem is this code:

 String file2 = System.getProperty("C:/Users/newproject/lib/IEDriverServer.exe");

Which is asking for a property called "C:/Users/newproject/lib/IEDriverServer.exe".  (In the others you're asking for "user.dir").

If this returns null (which it will) then the call to setProperty() will throw a NullPointerException because you're setting a "null" value.  Which isn't allowed.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I think we covered this pretty well.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.