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
Amro
  • 123,847
  • 25
  • 243
  • 454
jcfrei
  • 1,819
  • 4
  • 19
  • 35
  • 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`? – zapl Sep 01 '13 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 – jcfrei Sep 01 '13 at 13:16
  • 2
    similar question: [importing java classes in matlab classdef](http://stackoverflow.com/q/16407337/97160) – Amro Sep 01 '13 at 21:55

1 Answers1

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.

Oleg
  • 10,406
  • 3
  • 29
  • 57