Error: The superclass, ‘Animal’, has no unnamed constructor that takes no arguments.
Problem Description:
Because the constructor cannot inherit
an error is reported during inheritance, which prompts that the constructor in the parent class is composed of parameters. You need to write the constructor in the subclass and pass the constructor of the parent class to parameters
class Animal {
String name;
int age;
Animal(this.name, this.age);
void printInfo() {
print('$name is $age years old');
}
}
//Inherit Animal class by extends keyword
class Cat extends Animal {
}
void main(List<String> args) {
Cat cat = new Cat();
print( cat.name);
}
Solution:
Super keyword
Try declaring a zero argument constructor in ‘Animal’, or declaring a constructor in Cat that explicitly invokes a constructor in ‘Animal’.dart(no_default_super_constructor)
Try declaring a zero parameter constructor in “animal” or a constructor that explicitly calls the constructor in “animal” in cat.dart (no default super constructor)
class Animal {
String name;
int age;
Animal(this.name, this.age);
void printInfo() {
print('$name is $age years old');
}
}
//Inherit Animal class by extends keyword
class Cat extends Animal {
Cat(String name, int age) : super(name, age);
}
void main(List<String> args) {
Cat cat = new Cat("Huahua",3);
print( cat.name);
}
Read More:
- [Solved] Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“
- [Solved] volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
- Pyqt5 Error: AttributeError: ‘QWidget‘ object has no attribute ‘setCentralWidget‘
- IText The document has no pages [How to Solve]
- Pytorch error: `module ‘torch‘ has no attribute ‘__version___‘`
- [Jeston Xavier NX Compile librealsense Error] AttributeError: module ‘pyrealsense2‘ has no attribute ‘pipeline‘
- [Solved] redis Error: AttributeError: ‘list‘ object has no attribute ‘decode‘
- Numpy.exp Function Error ‘Float’ object has no attribute ‘exp’
- PySpark error: AttributeError: ‘NoneType‘ object has no attribute ‘_jvm‘
- [Solved] Module ‘scipy.misc‘ has no attribute ‘imread‘
- module ‘networkx’ has no attribute ‘from_pandas_dataframe’
- [Solved] AttributeError : ‘GridSearchCV‘ object has no attribute ‘grid_scores_‘
- [Solved] This application has no explicit mapping for /error, so you are seeing this as a fallback
- This application has no explicit mapping for /error, so you are seeing this as a fallback.
- [Solved] AttributeError: ‘depthai.node.ObjectTracker‘ object has no attribute ‘setTrackerIdAssigmentPolicy‘
- [Solved] AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
- [Solved] OpenCV Error: AttributeError: module ‘cv2‘ has no attribute ‘data‘
- [Solved] IDEA Git Update Error: Master has no tracked branch
- [How to Solve] Tesorflow: module ‘pandas.core.computation’ has no attribute ‘expressions’
- JSP error: The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path