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 CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by