java 找不到符号错误?

发布于 2024-10-11 13:54:10 字数 3165 浏览 3 评论 0原文

我收到此错误:

   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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

苹果你个爱泡泡 2024-10-18 13:54:10

JTable 的构造函数需要参数 (Object[][] rowData, Object[] columnNames)。因此,在调用该构造函数时,您需要使用该类型的值来调用它。

String[] 作为 Object[] 传递是没有问题的(因为 String 是一个 Object,但是传递 < code>float[][] as Object[][] 无效(因为 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[] as Object[] is no problem (because a String is an Object, but passing float[][] as Object[][] is not valid (because a float is not an Object).

With Java5 the "boxing" of primitive type (like float) into wrapper objects (like Float) became possible. This means, that Float 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 type Float[][].

凉薄对峙 2024-10-18 13:54:10

您不能使用基本类型的多维数组。您需要使用对象的多维数组。

这是无效的:

float[][] arr;

这是有效的:

Float[][] arr;

You can't use a multidimensional array of primitive types. You need to use a multidimensional array of objects.

This is invalid:

float[][] arr;

This is valid:

Float[][] arr;
剑心龙吟 2024-10-18 13:54:10

float 是原始类型,而不是对象。

float is a primitive type, not an object.

故事还在继续 2024-10-18 13:54:10

请参阅 Javadocs。您可能需要创建一个 Float[][] (对象)

See the Javadocs. You probably need to make a Float[][] (the object)

烟燃烟灭 2024-10-18 13:54:10

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...

筑梦 2024-10-18 13:54:10
JTable(Object[][] rowData, Object[] columnNames) 

http://download.oracle.com/javase /1.5.0/docs/api/javax/swing/JTable.html

构造一个 JTable 以显示二维数组 rowData 中的值以及列名 columnNames。

如前所述,构造函数接受对象,不能传递原始多维数组。

JTable(Object[][] rowData, Object[] 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.

梦归所梦 2024-10-18 13:54:10

JTable 期望第一个参数扩展 Object[][]float 是原始类型,不扩展 ObjectFloat 是一个这样做的对象。改用它。

There is no matching constructor for JTable which expects the first parameter to extend Object[][]. float is a primitive type and does not extend Object. Float is an object which does. Use it instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文