Java Android-类的空构造函数也会给出错误
我从另一个类继承了一个类,但首先我未能给出空构造函数。但是在编写空构造函数之后,我的应用程序仍然给出相同的错误 错误:Java Android-类的空构造函数也会给出错误,java,android,inheritance,Java,Android,Inheritance,我从另一个类继承了一个类,但首先我未能给出空构造函数。但是在编写空构造函数之后,我的应用程序仍然给出相同的错误 错误: java.lang.InstantiationException: can't instantiate class com.example.test3.VideoRecorder; no empty constructor 这是我正在使用的普通构造函数,它可以正常工作: public Videoplanner(Context ctxt, String logTag,Appli
java.lang.InstantiationException: can't instantiate class com.example.test3.VideoRecorder; no empty constructor
这是我正在使用的普通构造函数,它可以正常工作:
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;
}
现在,错误带有空构造函数,它给出了错误
public Videoplanner()
{
super(null, null);
}
我也试过了
static Context context;
static String str;
public Videoplanner()
{
super(context,str);
}
但这仍然给了我同样的错误。有人能帮忙吗?如果您在类中创建任何自定义的
构造函数
,那么编译器
不会提供默认的空构造函数
。在这种情况下,如果要创建该类的对象
,而不使用参数构造函数
,则必须提供空的构造函数
您不必为类提供任何构造函数,但是
做这件事时一定要小心。编译器自动提供
没有参数,没有构造函数的任何类的默认构造函数。
此默认构造函数将调用
超类。在这种情况下,如果
超类没有无参数构造函数,因此必须验证
确实如此。如果您的类没有显式超类,那么它有一个
对象的隐式超类,它没有参数
构造器
参考您的错误提到了
录像机
,但您正在显示Videoplanner
的代码。您确定要修改正确的类吗?错误。错误在继承此子类的类中。已更正。非常感谢!