Passing javaArray to java method, error: No method 'getArray' with matching signature found for class

조회 수: 2 (최근 30일)
On Matlab Part:
Test = Test_abc; % Refer to Class Test_abc
data = javaArray('java.lang.Float',2,3);
for i=1:2
for j = 1:3
data(i,j)=java.lang.Float(i+j);
end
end
list_index = 2; % another int number to be passed to java method
Test.getArray(list_index-1, data);
On Java Part:
public class Test_abc{
...
public void getArray(int number, float[][] Mat_data)
{
System.out.println("Java accepts the value" + Mat_data[0][0] + ".");
System.out.println("Java accepts the value" + Mat_data[1][1] + ".");
}
...
}
Then the error
No method 'getArray' with matching signature found for class Test_abc
would pop up. What's strange is that if one normal matlab matrix element is passed, like " Test.getArray(list_index-1, X(1,1)); ", where X = [1,2; 3,4], there's no problem. I'm most sure that the problem lies in the conversation:
Test.getArray(list_index-1, data);
public void getArray(int number, float[][] Mat_data);
Why can't I pass a javaArray from matlab to java? Thank you!

채택된 답변

Malcolm Lidierth
Malcolm Lidierth 2012년 10월 23일
편집: Malcolm Lidierth 2012년 10월 23일
float (with no capital letter) is a primitive data type in Java
Float (with capital) is a 'boxed' primitive - a true Java object.
You are passing a Float array to getArray but specifying float in the method's signature.
For float, just use a MATLAB 'single' array.
  댓글 수: 1
Pengfei
Pengfei 2012년 10월 23일
Thank you soooooooo much, my life saver!!! I've spent the whole day struggling with it, as a Java beginner.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Java from MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by