Unable to use Java class in a package - Undefined function or variable 'CartesianCoordinate'.
10 views (last 30 days)
Show older comments
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274053/image.png)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274054/image.png)
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 ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274055/image.png)
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.
0 Comments
Answers (1)
Yair Altman
on 3 Mar 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
See Also
Categories
Find more on Call Java from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!