Given class Award :
public class Award {
/*
*
*/
// fields of the class
Award()
{
// some initializations
}
I’m trying to invoke this constructor from Main :
try
{
Award myAward = Award.class.getConstructor().newInstance();
myAward.calculateAward();
}
catch (Exception e)
{
e.printStackTrace();
}
but it goes into the exception block and produces NoSuchMethodException exception .
What’s wrong ?
Thanks !
The issue is your constructor is not
publicso you will need to usegetDeclaredConstructor().newInstance();or make the constructorpublic.