how to invoke java program from matlab

2 visualizaciones (últimos 30 días)
Neha
Neha el 23 de Mayo de 2011
I have to run following code in java and invoke this class in matlab. Classpath is set as recommended.
class HelloWorld
{
public String Hello()
{
String helloWorld="Hello World!";
return helloWorld;
}
}
Now, as per guided i try to create instance obj in Matlab, with following command:
o = HelloWorld;
Here I get following err:
No constructor 'HelloWorld' with matching signature found.
The next command indicated it this:
output = o.hello;
which wouldnt work unless instance is created. Plz help how to fix this instance creation.

Respuestas (1)

Neha
Neha el 23 de Mayo de 2011
I modified this code as follows, by including package:
package pkg1;
public class HelloWorld
{
public HelloWorld()
{
HelloWorld h = HelloWorld();
}
public String hello()
{
String helloWorld = "HelloWorld!";
return helloWorld;
}
}
Now following instructions executed:: |--> keep this file in a package called pkg1. --> Run and compile as an ordinary Java Package File, so as to create .class files. --> now your package will be stored in matlab work folder. --> so your package path is C:\Matlab\Work\pkg1 --> ------------------------------ | Now i executed following function on matlab command window:
import pkg1.*;
obj = h;
str1 = obj.hello();
Yet i have same error as mentioned above.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by