Unable to use Java class in a package - Undefined function or variable 'CartesianCoordinate'.

13 visualizaciones (últimos 30 días)
Hi seniors,
I've been using java classes in Matlab for a while. But today, the error "Undefined function or variable 'CartesianCoordinate'." happened when I wanted to use the class called CartesianCoordinate. I've checked what I know e.g., the path and everything is fine. I'm quite confused why this happened. It's hard to understand the problem by text so, please let me explain with some figures.
I've included the following three pathes into the STATIC JAVA PATH:
I have some classes in the folder C:\Users\qw953\SUMO\sumo_files\Demos\Matlabfiles\Java\Lab3Test All the classes in this directory work perfectly. I use them in a simple way in Matlab. For example, m = Lab3Test; Then I'm able to call methods of the specific class.
However, when I want to use the class CartesianCoordinate in geometry folder (geometry is a package), the error happened. I assume the class LineSegment wouldn't work as well. But I have no idea what the reason is since I've already added C:\Users\qw953\SUMO\sumo_files\Demos\Matlabfiles\Java\Lab3Test\geometry into javaclasspath.txt and the corresponding .class files are right there. Is this possibly because classes in Lab3Test imported classes in geometry ?
Then what I did is moving the class CartesianCoordinate to Lab3Test folder, then it can be used as normal. Is it still because the class path related issue is not sorted?
I hope I have made the problem clear enough. Please help me with this and thank you in advance.

Respuestas (1)

Yair Altman
Yair Altman el 3 de Mzo. de 2020
This problem could be due to numerous possible causes, and unfortunately Matlab is not very helpful in explaining the root cause. See here: http://undocumentedmatlab.com/articles/java-class-access-pitfalls
  1 comentario
QIAO WANG
QIAO WANG el 3 de Mzo. de 2020
Thanks for your reply. Actually, I found another similar question posted 10 years ago and the accepted answer was clear enough for me. This problem is due to that I wanted to use classes included in a java package. So, what's needed to do in addition is by importing that package.
I've tested and it's working for me now. Thank you anyway.

Iniciar sesión para comentar.

Categorías

Más información sobre Call Java from MATLAB en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by