我有“;”预期的
错误,我已经尝试添加“;”但徒劳。这是代码:
public static XYZDataset createDataset(JTable table )
{
DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset();
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
double[][] ad = new double[nRow][1];
double[][] ad1 = new double[nRow][1];
double[][] ad2 = new double[nRow][1];
double ad3[][]=null;
for (int i = 0 ; i < nRow ; i++)
{
ad[i] = (double[]) dtm.getValueAt(i,1);
ad1[i] = (double[]) dtm.getValueAt(i,2);
ad2[i] = (double[]) dtm.getValueAt(i,3);
ad3[][]={ad[i],ad1[i],ad2[i]} ;
}
defaultxyzdataset.addSeries( "Series 1" , ad3 );
return defaultxyzdataset;
}
我在这一行遇到错误:ad3[][]={ad[i],ad1[i],ad2[i]}
最佳答案
尝试
public static XYZDataset createDataset(JTable table )
{
DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset();
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
double[][] ad = new double[nRow][1];
double[][] ad1 = new double[nRow][1];
double[][] ad2 = new double[nRow][1];
double ad3[][][]= new double[nRow][3][1];
for (int i = 0 ; i < nRow ; i++)
{
ad[i] = (double[]) dtm.getValueAt(i,1);
ad1[i] = (double[]) dtm.getValueAt(i,2);
ad2[i] = (double[]) dtm.getValueAt(i,3);
ad3[i]={ad[i],ad1[i],ad2[i]} ;
}
defaultxyzdataset.addSeries( "Series 1" , ad3 );
return defaultxyzdataset;
}
您当前的代码实际上正在尝试将数组分配给空值,因为如果 [] 中没有一些数字,ad3[][] 就没有解释意义。
关于java - 如何解决Java中预期的分号错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30008964/