Maxi Dee
Maxi Dee

Reputation: 61

Why am I getting a "cannot find symbol" error in Java?

@Override
public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected,
        boolean hasFocus, int row, int col) {

    // *** here  *** 
    Component c = super.getTableCellRendererComponent(table, value, isSelected, 
               hasFocus, row, col); 

    // Formatting here
    return c;
}

I'm getting an error in the indicated line. It says "cannot find symbol" but I can't realize what the real problem is.


Updated

@martinusadyh

I'm afraid the class is too big so it doesn't allow me to paste it here.

@ Hovercraft Full Of Eels

here's the error in Netbeans
https://i.sstatic.net/R4fv3.jpg

@Henery

It's not my class. I'm only implementing an interface method.

Upvotes: 2

Views: 2968

Answers (2)

Martijn Courteaux
Martijn Courteaux

Reputation: 68887

You have to extends DefaultTableCellRenderer instead of implements TableCellRenderer.


Note: DefaultTableCellRenderer its method getTableCellRendererComponent returns this. This means that it's enough to call the super.getTableCellRendererComponent(); without assigning it to a local variable. Because the local variable equals this. Maybe my explanation is too difficult: example.

public class MyTableCellRenderer extends DefaultTableCellRenderer
{

    @Override
    public Component getTableCellRendererComponent(
            JTable table, Object value, boolean isSelected,
            boolean hasFocus, int row, int col) {

        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); 

        // Formatting here
        setIcon(myCustomIcon);
        setText(myCustomText);

        return this;
    }

}

Upvotes: 2

A.H.
A.H.

Reputation: 66263

It's not mine that class, i'm only implementing an interface's method.

Then your parent class super is Object and has no method getTableCellRendererComponent. You either have to extend a suitable class or get along without calling non-existing methods.

Upvotes: 3

Related Questions