razshan
razshan

Reputation: 1138

Cannot find symbol error on java?

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();    } 

}}

Upvotes: 3

Views: 3693

Answers (7)

brian_d
brian_d

Reputation: 11395

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.

Upvotes: 0

fmucar
fmucar

Reputation: 14558

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.

Upvotes: 0

slartidan
slartidan

Reputation: 21608

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

Upvotes: 2

AlexR
AlexR

Reputation: 115378

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

Upvotes: 0

Robert
Robert

Reputation: 6540

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

Upvotes: 0

Aito
Aito

Reputation: 6872

float is a primitive type, not an object.

Upvotes: 0

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181380

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;

Upvotes: 2

Related Questions