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

조회 수: 17 (최근 30일)
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.

답변 (1개)

Yair Altman
Yair Altman 2020년 3월 3일
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
QIAO WANG
QIAO WANG 2020년 3월 3일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Java from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by