Why can I not import my Java classes that are declared as part of a package?

14 views (last 30 days)
If I have a class named "test.class" that is declared as part of package "pack", I get an undefined function error when I try to import the file.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The following code produces an "undefined function or variable 'test'" error:
javaaddpath('<root_directory>\pack');
import test.*
methodsview(test)
The source of the error is that a Java package is similar to directory. Although the directory that contains the class file has been added to the Java path, the class is still expected to be contained in a subdirectory "pack". You can fix this problem using the following code:
javaaddpath('<root_directory>');
import pack.test.*
methodsview(test)
If 'pack' is a JAR archive (.jar file), it may also be added to the Java class path as follows:
javaaddpath('<root_directory>\pack.jar');

More Answers (0)

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!