views:

261

answers:

3

Hi, I have read the documentation and several websites on exactly how to do this, however Matlab does not seem to pick up the classes that I have added to the dynamic java class path. Nor do I use the right syntax to correctly construct the object.

I have an class HandDB and which to create an object of this type and invoke it's static methods to connect to a SQL database. The class has an empty constructor and takes no parameters. The class is part of a package 'nuffielddb' which I made in a project within Netbeans. All the files are on my usb stick which is my E:\ drive...

I would like to be able to use all the classes within the package. The package is contained at E:\nuffielddb.

I entered the following commands into Matlab:

javaaddpath('E:\'); 
javaclasspath;    % Output from java class path includes E:\ within dynamic path
str = java.lang.String('Test'); % Works fine
db = nuffieldbd.HandDB(); % Does not work - undefined variable or class error

Interesting I typed 'import nuffielddb.*;' and received no error.

Just where am I going wrong?

Thanks for your help btw!

A: 

Ah problem solved! Well not solved in a sense! I found out it's actually a problem with my matlab installation and I have no idea how to fix it :-( Never mind, it works on the computers at the office :-)

Graham
Re-installed Matlab problem solved.
Graham
A: 

if your classes are in a .jar file, make sure your classpath includes the .jar file name itself (not just the directory it's in).

Also if the MATLAB JRE is Java 1.5 (R2006b is, whereas R2009a is Java 1.6, not sure when they switched), make sure your classes are compiled with 1.5 as a target, not 1.6, otherwise MATLAB will not be able to use them.

Jason S
just FYI: ML R14SP3 uses java 1.5 also (R13 used 1.4.2, I think R14SP2 used 1.4.2 also but I no longer have that installed)
KitsuneYMG
A: 

Minor note: .* imports will never error, so they're not diagnostic. They simply add a package to the list that Matlab searches through when trying to resolve a class name. Nonexistent packages are ignored.

>> import this.package.does.not.exist.*
>>
Andrew Janke