0

Im getting started with OOP in matlab. However using java objects in my code causes me quite a bit of a headache. Specifically I run into this error when I try to run testClass.start():

Undefined function 'SessionSettings' for input arguments of type 'char'.

The mentioned function is present in the jar which gets imported and the code is running fine if it's run outside of a matlab class. here's the class:

classdef testClass

 properties
     data
 end

 methods

      function obj = testClass()
         % class constructor
         javaaddpath /home/test/test-examples-1.5.3.jar;
         import test.examples.thingy.*;

      end


     function ret = start()
         % 
         settings = sessionSettings('configFilePath');
      end
 end

end
3
  • It looks like it tries to find a method named SessionSettings(char arg1) which does not exist in your jar. Maybe it takes a String? Commented Sep 1, 2013 at 13:14
  • the method actually exists in the jar, and if I run the above code outside of a class, then it works. Ie. just running: javaaddpath /home/test/test-examples-1.5.3.jar; import test.examples.thingy.*; settings = sessionSettings('configFilePath'); works Commented Sep 1, 2013 at 13:16
  • 2
    similar question: importing java classes in matlab classdef Commented Sep 1, 2013 at 21:55

1 Answer 1

1

Citing the documentation of import():

The import function only affects the import list of the function within which it is used. When invoked at the command prompt, import uses the import list for the MATLAB® command environment. If import is used in a script invoked from a function, it affects the import list of the function. If import is used in a script that is invoked from the command prompt, it affects the import list for the command environment.

The import list of a function is persistent across calls to that function and is only cleared when the function is cleared.

This means, that your method start() will see an empty import list.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.