Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fails to load/import java class

Subject: fails to load/import java class

From: Bart Thijs

Date: 21 Feb, 2010 01:24:03

Message: 1 of 8

Hi,

I've some problems with using my own java package in Matlab.
I've put the jar-package in the static java path.
When I run the javaclasspath command I can see my jar in the list.

After import of the class Matlab fails to use it

The function methodview gives this error:
??? Error using ==> methodsview at 65
No class MyClass can be located or no methods for class MyClass

Can someone help me?

best regards
Bart

Subject: fails to load/import java class

From: Yair Altman

Date: 21 Feb, 2010 06:51:04

Message: 2 of 8

"Bart Thijs" <bart.thijs@econ.kuleuven.be> wrote in message <hlq1vj$ffk$1@fred.mathworks.com>...
> Hi,
>
> I've some problems with using my own java package in Matlab.
> I've put the jar-package in the static java path.
> When I run the javaclasspath command I can see my jar in the list.
>
> After import of the class Matlab fails to use it
>
> The function methodview gives this error:
> ??? Error using ==> methodsview at 65
> No class MyClass can be located or no methods for class MyClass
>
> Can someone help me?
>
> best regards
> Bart

Either you misspelled your class name (note case sensitivity), or none of your class's methods were declared "public".

Yair Altman
http://UndocumentedMatlab.com

Subject: fails to load/import java class

From: Bart Thijs

Date: 22 Feb, 2010 14:54:05

Message: 3 of 8

Hi Yair,

Thanks for your suggestion but both issues are not the case.
All the methods are public and i used copy/paste.

I find it very difficult that you get no error message from Matlab when importing a java class. Is there a possibility to check for all loaded classes.
I've seen something like [m,x,j]=inmem but this gives only empty arrays.

I've tried to include all the used packages in my jar and I can use this jar succesfully outside of Matlab in a jar so every thing seems to be OK with the jar file.

Subject: fails to load/import java class

From: Lei Chen

Date: 18 Mar, 2010 09:14:04

Message: 4 of 8

"Bart Thijs" <bart.thijs@econ.kuleuven.be> wrote in message <hlu5qd$a57$1@fred.mathworks.com>...
> Hi Yair,
>
> Thanks for your suggestion but both issues are not the case.
> All the methods are public and i used copy/paste.
>
> I find it very difficult that you get no error message from Matlab when importing a java class. Is there a possibility to check for all loaded classes.
> I've seen something like [m,x,j]=inmem but this gives only empty arrays.
>
> I've tried to include all the used packages in my jar and I can use this jar succesfully outside of Matlab in a jar so every thing seems to be OK with the jar file.

I actually have the same problem when I use a third party jar file. Like what you said, if you run javaclasspath, you will see your jar is there, and when you import, there is nothing wrong. But when you call the classes. it says undefined. I am still trying to solve it.

Subject: fails to load/import java class

From: Yair Altman

Date: 18 Mar, 2010 14:33:06

Message: 5 of 8

"Lei Chen" <chlpd@hotmail.com> wrote in message <hnsqss$j0j$1@fred.mathworks.com>...
> "Bart Thijs" <bart.thijs@econ.kuleuven.be> wrote in message <hlu5qd$a57$1@fred.mathworks.com>...
> > Hi Yair,
> >
> > Thanks for your suggestion but both issues are not the case.
> > All the methods are public and i used copy/paste.
> >
> > I find it very difficult that you get no error message from Matlab when importing a java class. Is there a possibility to check for all loaded classes.
> > I've seen something like [m,x,j]=inmem but this gives only empty arrays.
> >
> > I've tried to include all the used packages in my jar and I can use this jar succesfully outside of Matlab in a jar so every thing seems to be OK with the jar file.
>
> I actually have the same problem when I use a third party jar file. Like what you said, if you run javaclasspath, you will see your jar is there, and when you import, there is nothing wrong. But when you call the classes. it says undefined. I am still trying to solve it.


place the jar filepath in your static java classpath. To do this, simply type: "edit classpath.txt" in your Matlab Command Window and after adding your JAR(s) restart Matlab

Yair Altman
http://UndocumentedMatlab.com

Subject: fails to load/import java class

From: Lei Chen

Date: 20 Mar, 2010 09:42:05

Message: 6 of 8

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hntdj2$l6g$1@fred.mathworks.com>...
> "Lei Chen" <chlpd@hotmail.com> wrote in message <hnsqss$j0j$1@fred.mathworks.com>...
> > "Bart Thijs" <bart.thijs@econ.kuleuven.be> wrote in message <hlu5qd$a57$1@fred.mathworks.com>...
> > > Hi Yair,
> > >
> > > Thanks for your suggestion but both issues are not the case.
> > > All the methods are public and i used copy/paste.
> > >
> > > I find it very difficult that you get no error message from Matlab when importing a java class. Is there a possibility to check for all loaded classes.
> > > I've seen something like [m,x,j]=inmem but this gives only empty arrays.
> > >
> > > I've tried to include all the used packages in my jar and I can use this jar succesfully outside of Matlab in a jar so every thing seems to be OK with the jar file.
> >
> > I actually have the same problem when I use a third party jar file. Like what you said, if you run javaclasspath, you will see your jar is there, and when you import, there is nothing wrong. But when you call the classes. it says undefined. I am still trying to solve it.
>
>
> place the jar filepath in your static java classpath. To do this, simply type: "edit classpath.txt" in your Matlab Command Window and after adding your JAR(s) restart Matlab
>
> Yair Altman
> http://UndocumentedMatlab.com

Thanks, Yair,
Yes, I did that, and I am quite sure classpath.txt is edited and jar files are there. I am using a third party ones, and their instructions is like this also. So, I am still not sure what is wrong. I also checked with other matlab versions, not working either. But if you have time, I can send you the jar file for a test....

/Lei

Subject: fails to load/import java class

From: Yair Altman

Date: 20 Mar, 2010 17:23:03

Message: 7 of 8

"Lei Chen" <chlpd@hotmail.com> wrote...
[...]
> So, I am still not sure what is wrong. I also checked with other matlab versions, not working either. But if you have time, I can send you the jar file for a test....
>
> /Lei


I am a professional consultant, so if you will be willing to compensate me for my time and effort, then I will be happy to help. Feel free to email me.

Yair Altman
http://UndocumentedMatlab.com

Subject: fails to load/import java class

From: Mohsen

Date: 31 Mar, 2010 23:08:07

Message: 8 of 8

On Mar 20, 9:23 am, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> "Lei Chen" <ch...@hotmail.com> wrote...
>
> [...]
>
> > So, I am still not sure what is wrong. I also checked with other matlab versions, not working either. But if you have time, I can send you the jar file for a test....
>
> > /Lei
>
> I am a professional consultant, so if you will be willing to compensate me for my time and effort, then I will be happy to help. Feel free to email me.
>
> Yair Altmanhttp://UndocumentedMatlab.com

Hi, I am not a professional consultant :D However I had the same
problem and apparently it is because of the version of java being used
in your Matlab and in your java code. Make sure they are using the
same version. For example I was compiling my code using jdk 1.6 while
my Matlab was using jdk 1.5. I changed my main java to 1.5 and then
Matlab was able to load the jar file.

Hope this helps.

Best,
Mohsen

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us