I get a java.lang.NoSuchMethodError when using a java.nio.DirectByteBuffer
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dennis van den Berg
am 30 Aug. 2019
Beantwortet: Dennis van den Berg
am 4 Sep. 2019
I created a java library which I need to use in Matab. I narrowed it down to the following code.
My java class:
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class MyClass {
public void test() {
ByteBuffer bb = ByteBuffer.allocateDirect(100).order(ByteOrder.nativeOrder());
System.out.println(bb.getClass().getName());
bb.flip();
}
}
When using the class in Matlab as follows:
>> import MyClass
>> a = MyClass;
>> a.test
I get the following output:
java.nio.DirectByteBuffer
Java exception occurred:
java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
at MyClass.test(MyClass.java:13)
Since Buffer has the flip method and is a superclass of DirectByteBuffer, DirectByteBuffer should definitely have the method. The java code works when I run it on a regular JVM outside Matlab.
7 Kommentare
Kojiro Saito
am 4 Sep. 2019
Yes, as of R2019a, MATLAB's Java (JRE) version is 8. So, you need to use JDK 8. I have also tested to build you java code in JDK 9, but in that case, MATLAB shows an error (Import argument 'MyClass' cannot be found or cannot be imported.).
I'm not sure when Java 11 will be supported. But there is a way to change Java version from that of built-in as described in this answer, so you might use Java 11.
Also, for house keeping, could you post your answer by yourself and accept it?
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Java Package Integration 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!