java 找不到符号错误?
我收到此错误:
symbol : constructor JTable(float[][],java.lang.String[])
location: class javax.swing.JTable
table = new JTable(dataValues, columnNames );
下面是代码
import java.awt.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
import javax.swing.table.*;
public class benchtesting extends JFrame
{
private JTabbedPane tabbedPane;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JTable table;
private JScrollPane scrollPane;
public static void main( String args[] )
{
benchtesting mainFrame = new benchtesting();
mainFrame.setVisible( true );
}
public benchtesting()
{
setSize(280,200);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocation(1300,280);
setTitle("Photoreceptor Analysis");
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create the tab pages
createPage1();
// createPage2();
// createPage3();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
tabbedPane.addTab( "Table", panel1 );
tabbedPane.addTab( "Intensity Map", panel2 );
tabbedPane.addTab( "Notes", panel3 );
topPanel.add( tabbedPane, BorderLayout.CENTER );
}
public void createPage1()
{
panel1 = new JPanel();
panel1.setLayout( new BorderLayout() );
float dataValues_all[]= new float[400];
BufferedReader inputFile2=null;
BufferedReader inputFile=null;
try {
FileReader freader =new FileReader("results.txt");
inputFile2 = new BufferedReader(freader);
String read = "";
String number ="";
for (int linenum=0; linenum<400; linenum++) {
read = inputFile2.readLine();
if(read != null && read.startsWith("D"))
{
number = read.substring(9,15);
float real_numbers = Float.parseFloat(number);
real_numbers= real_numbers*2817217;
System.out.println(Math.round(real_numbers)+" cells/mm^2");
dataValues_all[linenum] = real_numbers;
}
}
// System.out.println("hmm "+dataValues_all[398]);
String columnNames[] = {"1","2","3","4","5","6","7","8","9","10"};
float dataValues[][]= new float [1][10]; //1 row, 10 coloumns
dataValues[0][0] = dataValues_all[2];
dataValues[0][1] = dataValues_all[6];
dataValues[0][2] = dataValues_all[10];
dataValues[0][3] = dataValues_all[14];
dataValues[0][4] = dataValues_all[18];
dataValues[0][5] = dataValues_all[22];
dataValues[0][6] = dataValues_all[26];
dataValues[0][7] = dataValues_all[30];
dataValues[0][8] = dataValues_all[34];
dataValues[0][9] = dataValues_all[38];
table = new JTable(dataValues, columnNames );
scrollPane = new JScrollPane(table);
panel1.add( scrollPane, BorderLayout.CENTER );
} catch( Exception y ) { y.printStackTrace(); }
}}
I am getting this error:
symbol : constructor JTable(float[][],java.lang.String[])
location: class javax.swing.JTable
table = new JTable(dataValues, columnNames );
below is the code
import java.awt.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
import javax.swing.table.*;
public class benchtesting extends JFrame
{
private JTabbedPane tabbedPane;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JTable table;
private JScrollPane scrollPane;
public static void main( String args[] )
{
benchtesting mainFrame = new benchtesting();
mainFrame.setVisible( true );
}
public benchtesting()
{
setSize(280,200);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocation(1300,280);
setTitle("Photoreceptor Analysis");
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create the tab pages
createPage1();
// createPage2();
// createPage3();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
tabbedPane.addTab( "Table", panel1 );
tabbedPane.addTab( "Intensity Map", panel2 );
tabbedPane.addTab( "Notes", panel3 );
topPanel.add( tabbedPane, BorderLayout.CENTER );
}
public void createPage1()
{
panel1 = new JPanel();
panel1.setLayout( new BorderLayout() );
float dataValues_all[]= new float[400];
BufferedReader inputFile2=null;
BufferedReader inputFile=null;
try {
FileReader freader =new FileReader("results.txt");
inputFile2 = new BufferedReader(freader);
String read = "";
String number ="";
for (int linenum=0; linenum<400; linenum++) {
read = inputFile2.readLine();
if(read != null && read.startsWith("D"))
{
number = read.substring(9,15);
float real_numbers = Float.parseFloat(number);
real_numbers= real_numbers*2817217;
System.out.println(Math.round(real_numbers)+" cells/mm^2");
dataValues_all[linenum] = real_numbers;
}
}
// System.out.println("hmm "+dataValues_all[398]);
String columnNames[] = {"1","2","3","4","5","6","7","8","9","10"};
float dataValues[][]= new float [1][10]; //1 row, 10 coloumns
dataValues[0][0] = dataValues_all[2];
dataValues[0][1] = dataValues_all[6];
dataValues[0][2] = dataValues_all[10];
dataValues[0][3] = dataValues_all[14];
dataValues[0][4] = dataValues_all[18];
dataValues[0][5] = dataValues_all[22];
dataValues[0][6] = dataValues_all[26];
dataValues[0][7] = dataValues_all[30];
dataValues[0][8] = dataValues_all[34];
dataValues[0][9] = dataValues_all[38];
table = new JTable(dataValues, columnNames );
scrollPane = new JScrollPane(table);
panel1.add( scrollPane, BorderLayout.CENTER );
} catch( Exception y ) { y.printStackTrace(); }
}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
JTable
的构造函数需要参数(Object[][] rowData, Object[] columnNames)
。因此,在调用该构造函数时,您需要使用该类型的值来调用它。将
String[]
作为Object[]
传递是没有问题的(因为String
是一个Object
,但是传递 < code>float[][] asObject[][]
无效(因为float
不是Object
)。使用 Java5,将原始类型(如
float
)“装箱”到包装对象(如Float
)中,这意味着 <。 code>Float a = 0.1f; 是有效的,但是装箱不适用于数组。解决您的问题的最佳解决方案可能是将变量
dataValues
更改为Float[ ][]
。The constructor of
JTable
expects the arguments(Object[][] rowData, Object[] columnNames)
. So when calling that constructor you need to call it with values of that types.Passing
String[]
asObject[]
is no problem (because aString
is anObject
, but passingfloat[][]
asObject[][]
is not valid (because afloat
is not anObject
).With Java5 the "boxing" of primitive type (like
float
) into wrapper objects (likeFloat
) became possible. This means, thatFloat a = 0.1f;
is valid. However boxing is not available for arrays.Probably the best solution for your problem is to change your variable
dataValues
to typeFloat[][]
.您不能使用基本类型的多维数组。您需要使用对象的多维数组。
这是无效的:
这是有效的:
You can't use a multidimensional array of primitive types. You need to use a multidimensional array of objects.
This is invalid:
This is valid:
float 是原始类型,而不是对象。
float is a primitive type, not an object.
请参阅 Javadocs。您可能需要创建一个
Float[][]
(对象)See the Javadocs. You probably need to make a
Float[][]
(the object)JTable 类确实没有接受二维浮点数组和常规字符串数组的构造函数。它有构造函数
JTable(Object[], String[])
因此,只需将
float dataValues[][]= new float [1][10];
更改为
Object dataValues[][]= new Object [1][10];
并享受。对自动装箱说“谢谢”...
JTable class really does not have constructor that accepts 2 dimensional float array and regular string array. It has constructor
JTable(Object[], String[])
So, just change
float dataValues[][]= new float [1][10];
to
Object dataValues[][]= new Object [1][10];
and enjoy. Say "thanks" to autoboxing...
http://download.oracle.com/javase /1.5.0/docs/api/javax/swing/JTable.html
构造一个 JTable 以显示二维数组 rowData 中的值以及列名 columnNames。
如前所述,构造函数接受对象,不能传递原始多维数组。
http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/JTable.html
Constructs a JTable to display the values in the two dimensional array, rowData, with column names, columnNames.
As stated already, constructor takes object, you can't pass primitive multidimensional array.
JTable 期望第一个参数扩展
Object[][]
。float
是原始类型,不扩展Object
。 Float 是一个这样做的对象。改用它。There is no matching constructor for JTable which expects the first parameter to extend
Object[][]
.float
is a primitive type and does not extendObject
. Float is an object which does. Use it instead.