java - Android - Empty constructor for a class also give error -


i inherited class class , first failed give empty constructor.but after writing empty constructor,my application still gives same error.

error:

java.lang.instantiationexception: can't instantiate class com.example.test3.videorecorder; no empty constructor 

here normal constructor using , works fine:

public videoplanner(context ctxt, string logtag,application app) throws nosuchalgorithmexception  {     super(ctxt, logtag);     telephonymanager telephonymanager = (telephonymanager) ctxt.getsystemservice(context.telephony_service);     messagedigest digester = messagedigest.getinstance("sha-1");     byte[] digest = digester.digest(telephonymanager.getdeviceid().getbytes());     hashedid = (new biginteger(1, digest)).tostring(16);     servicename = hashedid;     context = ctxt;     appl = app;  } 

now error comes empty constructor gives error

public videoplanner()  {     super(null, null);  } 

i tried

 static context context;  static string str;   public videoplanner()  {       super(context,str);  } 

but still gives me same error.can please help?

if create custom constructor in class compiler not provide default empty constructor. in case have provide empty constructor if want create object of class no-argument constructor.

you don't have provide constructors class, must careful when doing this. compiler automatically provides no-argument, default constructor class without constructors. default constructor call no-argument constructor of superclass. in situation, compiler complain if superclass doesn't have no-argument constructor must verify does. if class has no explicit superclass, has implicit superclass of object, have no-argument constructor.

reference documentation


Comments