Converting a cell array of strings to a char array for use with Java Strings

Converting a cell array of strings to a char array for use with Java Strings

Post by Michael Re » Sun, 12 Dec 2004 23:01:21


Hi, I am trying to call a Java function that takes a java.lang.String
using a Matlab cell array which has been converted to a char array
but it doesn't work.

a_cell = { 'This is the first line. ' char(10) ' the second line...'
};
a_char = char(a_cell);

jString2 = java.lang.String(a_char)

% >>> Error message: ??? No constructor java.lang.String
with matching signature found.

Whereas this works fine:
descr = ['This is a test ' 10 ' the second line..'];
jString = java.lang.String(descr)

What is wrong with that previous char array?

Michael
 
 
 

Converting a cell array of strings to a char array for use with Java Strings

Post by Michael Re » Sun, 12 Dec 2004 23:39:27

I just figured it out.

A char array has to be of dimension 1 by x or x by 1 to be compatible
with a java.lang.String.

Michael