MATLAB Answers

Passing Matrix List to Java Method ,error:No method 'list_method' with matching signature found for class

6 ビュー (過去 30 日間)
SAMEER ahamed
SAMEER ahamed 2014 年 3 月 4 日
編集済み: SAMEER ahamed 2014 年 3 月 6 日
Hi,
On Matlab Part :
matrix =[22,11,33,44,22,44,22,54]; % 1-by-8 matrix
if true
% code
import edu.lipreading.*;
import java.util.Vector;
training = MainMethod;
training.list_method(matrix);
end
On Java Part
if true
% code
public void list_method(List<Integer> points){
System.out.println("Welcome to List Method");
}
end
Note : When I have run my matlab code i got error like No method 'list_method' with matching signature found for class 'edu.lipreading.MainMethod'. // edu.lipreading Package Name ,MainMethod Class name

  1 件のコメント

SAMEER ahamed
SAMEER ahamed 2014 年 3 月 4 日
I have already asked look @ Passing List ,still awaiting for result .if any body know please let me know Thanks.

サインイン to comment.

採用された回答

Malcolm Lidierth
Malcolm Lidierth 2014 年 3 月 4 日
Try
public void list_method(double[] points){
...
}
Note that MATLAB vectors/matrices contain doubles by default and are passed to Java as a copy.

  3 件のコメント

SAMEER ahamed
SAMEER ahamed 2014 年 3 月 5 日
Thank's for reply me , my java code i need add list Items like
on Java Code :
public void list_method(List<Integer> points){
Sample recordedSample = new Sample ();
recordedSample.getMatrix().add(points);
}
on Matlab I have multiple dynamic matrices list values so i wanna need to add list method .
Example : matrix =[33,5,45,2,4,2,1,1]
[3,2,2,5,3,2,2,2]; etc.
SAMEER ahamed
SAMEER ahamed 2014 年 3 月 5 日
When I have change from java method argument List to double again i have got error below like
if true
% code
matrix
[12,34,113,34,61,1,61,66]
No method 'list_method' with matching signature found for class
'edu.lipreading.MainMethod'.
end
SAMEER ahamed
SAMEER ahamed 2014 年 3 月 5 日
When I have change from java method argument List to double again and again i have got error below like . Please reply me any idea ? thanks . please review previous forum for understanding ?
if true
% code
matrix
[12,34,113,34,61,1,61,66]
No method 'list_method' with matching signature found for class
'edu.lipreading.MainMethod'.
end

サインイン to comment.

その他の回答 (1 件)

Malcolm Lidierth
Malcolm Lidierth 2014 年 3 月 5 日
編集済み: Malcolm Lidierth 2014 年 3 月 5 日
OK, if you are stuck with a List java-side, you need to create a list MATLAB-side.
In MATLAB:
  • Create a concrete list class
list=java.util.ArrayList()
  • Add the elements to it
for k=1:length(matrix)
list.add(int32(matrix(k)));
end
  • Check its size:
>> list.size()
ans =
8
Note that the "<Integer>" annotation in your Java code is only relevant at compile time. Casting the MATLAB variable to int32 above ensures that the ArrayList will add a java.lang.Integer to the list at run-time. You could do that explicitly using
list.add(java.lang.Integer.valueOf(matrix(k)));
instead.
Within MATLAB you can access the list elements using "get":
e.g.
list.get(0)
Note that when MATLAB receives the returned Integer, it creates a MATLAB primitive double from it:
>> class(list.get(0))
ans =
double
Java will not - it will use the java.lang.Integer instance in the list.

  1 件のコメント

SAMEER ahamed
SAMEER ahamed 2014 年 3 月 6 日
Thanks for reply me below i have mentioned my full code , u can easily solve my issues.
On Matlab code-side
matrix =[33,122,3,2,2,3,2,4];
outsprintf=sprintf('%d,',matrix);
outsprintf=sprintf('[%s\b]',outsprintf);
disp(outsprintf);
here result is [33,122,3,2,2,3,2,4] like getting so this values i need to pass java method arguments List<Integer> points.
Note 2:About Java Class Please Look at my Attached file .

サインイン to comment.

サインイン してこの質問に回答します。

タグ

タグが未入力です。

製品


Translated by