Why do I get an error 'No constructor with matching signature found.' when construct a Java object that has been added to javaclasspath?
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 8 Feb. 2018
Beantwortet: MathWorks Support Team
am 26 Feb. 2018
I have a Java class with the following signatures:
package com.mathworks;
public class Test {
Test() {
System.out.println("Hello World!");
}
}
I have used the 'javaaddpath' properly to load the class into MATLAB. However, when I try to construct an object:
>> com.mathworks.Test();
I got the following error:
No constructor 'com.mathworks.Test' with matching signature found.
Akzeptierte Antwort
MathWorks Support Team
am 8 Feb. 2018
The reason is that the Java class constructor is not defined with an access modifier. Hence by default it will be treated as 'protected'.
This means that only classes in the same package would be able to access the constructor of this class.
You can find more information on access modifiers on Oracles website:
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
In order for MATLAB to construct an object of the class, please define the constructor as 'public' as the following:
package com.mathworks;
public class Test {
public Test() {
System.out.println("Hello World!");
}
}
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Call Java from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!