how to invoke java program from matlab

1 回表示 (過去 30 日間)
Neha
Neha 2011 年 5 月 23 日
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.

回答 (1 件)

Neha
Neha 2011 年 5 月 23 日
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.

カテゴリ

Help Center および File ExchangeJava Package Integration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by