错误类型不匹配,java.lang.String[][] 与 java.lang.String[] 不匹配
Error type mismatch, java.lang.String[][] does not match with java.lang.String[]
Table table;
String N;
String F;
String data;
String[] test = new String[1];
String stringcolumn;
//Here is where I assign all the variables.
void setup() {
table = loadTable("CVSTEST.csv", "header");
int rows = table.getRowCount();
int columns = table.getColumnCount();
//Get the row count and the table
for(int column = 0; column <= columns; column++){
for(int row = 0; row <= rows; row++){
//For every row in every column, assign data the input for later use
data = table.getString(rows,columns);
stringcolumn = Integer.toString(column);
test = new String[stringcolumn][data];
//Here is where the error occurs, I try to assign string column and data to the string array of test.
}
}
}
所以我在这个问题上停留了一段时间。我正在制作一个程序,当你把它放在 table,E.G
中时打印出数据
Name Score
Tim 513
但我一直 运行 陷入这个错误。我保存为浮点数是为了让它有条理,这样以后打印出来更容易,我可以在以后的代码中使用这些数据,并在以后进行比较。干杯。
我真的不明白你为什么要遍历数组。 Table
class 已经包含允许您从索引访问数据的函数。但即使您尝试做一些稍微不同的事情,希望这对您有所帮助:
你遇到了一些问题。第一关:
String[] test = new String[1];
这将您的 test
变量声明为一维 String
数组,长度为 1,这没有多大意义:如果它只会存储一个值吗?
如果要将其声明为二维 String
数组,可以这样做:
String[][] test;
请注意,这声明了数组,但尚未对其进行初始化。要对其进行初始化,您可能想知道二维数组的大小。我假设您想使用 table 中的列数和行数?如果是这样,你会这样做:
void setup() {
table = loadTable("CVSTEST.csv", "header");
int rows = table.getRowCount();
int columns = table.getColumnCount();
test = new String[rows][columns];
现在你的test
变量是一个二维数组,你可以把它想象成一个数组的数组。
接下来,这一行没有意义:
test = new String[stringcolumn][data];
你想在这里做什么?由于这是在嵌套的 for
循环中,因此它试图为 table 中的每个单元格创建一个新的二维数组。我猜想您真正想要做的是拥有一个二维数组,然后在这个嵌套的 for
循环中填充它的索引。像这样:
test[row][column] = data;
这会将位置 [row][column]
处的索引设置为等于 data
变量中的任何 String
。
Table table;
String N;
String F;
String data;
String[] test = new String[1];
String stringcolumn;
//Here is where I assign all the variables.
void setup() {
table = loadTable("CVSTEST.csv", "header");
int rows = table.getRowCount();
int columns = table.getColumnCount();
//Get the row count and the table
for(int column = 0; column <= columns; column++){
for(int row = 0; row <= rows; row++){
//For every row in every column, assign data the input for later use
data = table.getString(rows,columns);
stringcolumn = Integer.toString(column);
test = new String[stringcolumn][data];
//Here is where the error occurs, I try to assign string column and data to the string array of test.
}
}
}
所以我在这个问题上停留了一段时间。我正在制作一个程序,当你把它放在 table,E.G
中时打印出数据Name Score
Tim 513
但我一直 运行 陷入这个错误。我保存为浮点数是为了让它有条理,这样以后打印出来更容易,我可以在以后的代码中使用这些数据,并在以后进行比较。干杯。
我真的不明白你为什么要遍历数组。 Table
class 已经包含允许您从索引访问数据的函数。但即使您尝试做一些稍微不同的事情,希望这对您有所帮助:
你遇到了一些问题。第一关:
String[] test = new String[1];
这将您的 test
变量声明为一维 String
数组,长度为 1,这没有多大意义:如果它只会存储一个值吗?
如果要将其声明为二维 String
数组,可以这样做:
String[][] test;
请注意,这声明了数组,但尚未对其进行初始化。要对其进行初始化,您可能想知道二维数组的大小。我假设您想使用 table 中的列数和行数?如果是这样,你会这样做:
void setup() {
table = loadTable("CVSTEST.csv", "header");
int rows = table.getRowCount();
int columns = table.getColumnCount();
test = new String[rows][columns];
现在你的test
变量是一个二维数组,你可以把它想象成一个数组的数组。
接下来,这一行没有意义:
test = new String[stringcolumn][data];
你想在这里做什么?由于这是在嵌套的 for
循环中,因此它试图为 table 中的每个单元格创建一个新的二维数组。我猜想您真正想要做的是拥有一个二维数组,然后在这个嵌套的 for
循环中填充它的索引。像这样:
test[row][column] = data;
这会将位置 [row][column]
处的索引设置为等于 data
变量中的任何 String
。