close

[Solved] org.testng.TestNGException : Cannot instantiate class

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing the following error org.testng.TestNGException : Cannot instantiate class in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How org.testng.TestNGException : Cannot instantiate class Error Occurs?

Today I am facing the following error org.testng.TestNGException : Cannot instantiate class in Java.

How To Solve org.testng.TestNGException : Cannot instantiate class Error ?

  1. How To Solve org.testng.TestNGException : Cannot instantiate class Error ?

    To Solve org.testng.TestNGException : Cannot instantiate class Error Looking at the code, I understand the issue is in the constructor of the base class. LoginPageTest calls super() which invokes TestBase.

  2. org.testng.TestNGException : Cannot instantiate class

    To Solve org.testng.TestNGException : Cannot instantiate class Error Looking at the code, I understand the issue is in the constructor of the base class. LoginPageTest calls super() which invokes TestBase.

Solution 1

The lowest ’caused by’ section points you to the underlying exception in your base class constructor: you are calling System.getProperty with a file path; that will probably return null. To me it looks like the whole call shouldn’t be there, and you just want to pass the file path to the FileInputStream constructor (or read it from a system property with some key)

Solution 2

Looking at the code, I understand the issue is in the constructor of the base class. LoginPageTest calls super() which invokes TestBase.

FileInputStream needs a file path. I suspect FileInputSteam object created is coming as null.

Why are you calling System.getProperty? Is the config.properties file available?

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read