Problem instantiating a Java class

1 回表示 (過去 30 日間)
John
John 2014 年 8 月 7 日
回答済み: Stefan Slonevskiy 2018 年 10 月 8 日
I want to make use of the geometry classes in java.awt.geom.* in MATLAB. I can instantiate some classes like java.awt.geom.Area .But I cannot instantiate the static inner class java.awt.geom.Point2D.Double or any of its cousins, like java.awt.Point2D.Float .
For your reference, the package I am talking about is: http://docs.oracle.com/javase/7/docs/api/java/awt/geom/package-summary.html
At first I guessed it was because the Java runtime MATLAB installs does not have a complete set of standard classes.
So I added to the classpath (of a fresh MATLAB 2014a installation), $JRE_ROOT\lib\rt.jar using 'javaaddpath,' but I am still not able to instantiate java.awt.Point2D.Double . 'javaclasspath' confirms the rt.jar archive added to the DYNAMIC class path.
Then, trying to instantiate java.awt.geom.Point2D.Double gives the following error:
a = java.awt.geom.Point2D.Double(1, 1);
The class java.awt.geom.Point2D has no property or method named 'Double'.
Any idea why? I suspect it has to do either with: 1) MATLAB using the MATLAB JRE's java.awt.geom.point2D class before it looks into my Oracle JRE's rt.jar path, or 2) some syntactical problem with instantiating a JAVA static inner class within MATLAB.
PS: I looked through the "Answers" forum for very similar questions but could not find any, so apologies in advance if a very similar question happens to have been answered.

回答 (1 件)

Stefan Slonevskiy
Stefan Slonevskiy 2018 年 10 月 8 日
Just use this form:
a = javaObject('java.awt.geom.Point2D$Double',1,1)

カテゴリ

Help Center および File ExchangeCall Java from MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by