Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import -> 'cannot find symbol' | fully qualified name -> perfect

I have an inner class, which extends AbstractTableModel.

import javax.swing.table.AbstractTableModel;

public class MyClass extends MyAbstractClass {
    ...
    public static class MyTableModel extends AbstractTableModel {
    }
    ...
}

The compiler gives me the following error.

...\MyClass.java:190: error: cannot find symbol
         public static class MyTableModel extends AbstractTableModel {
                                                  ^
  symbol:   class AbstractTableModel
  location: class MyClass

When changing

MyTableModel extends AbstractTableModel

to

MyTableModel extends javax.swing.table.AbstractTableModel

everything works fine.

I use Gradle for building the project. Before I switched to Gradle, I used Eclipse to build the project. I didn't have the problem with Eclipse, the error only occurs, if I build with Gradle.

Do you have an idea what could be the reason for that strange behavior?

like image 911
Bilbo Avatar asked Sep 30 '22 13:09

Bilbo


1 Answers

The error was caused by my order of imports. MyTableModel contains a MyTableListener interface, which is also imported by MyClass.java.

import MyClass.MyTableModel.MyTableListener;
...
import javax.swing.table.AbstractTableModel;
...
public class MyClass extends MyAbstractClass {
...
   public static class MyTableModel extends AbstractTableModel {
       public interface MyTableListener {
           public void entryChanged();
       }
       ...
   }
...
}

When I put the MyTableListener import before the AbstractTableModel import Gradle gives me the cannot find symbol error.

When I put the AbstractTableModel import before the MyTableListener import everythings works fine.

So far so good, but why is the import order not a problem when building with Eclipse?!

like image 78
Bilbo Avatar answered Oct 02 '22 14:10

Bilbo