0

I can't understand why I'm getting the following error - cannot find symbol - class Line2D - when I try to compile this code:

import java.awt.*;

public class KochSegment
{
    public Line2D base = new Line2D(); public Line2D[] Lines = new Line2D[4]; //error is on this line

etc.
}
Elliot Gorokhovsky
  • 3,610
  • 2
  • 31
  • 56

2 Answers2

3

It's in a subpackage:

java.awt.geom.Line2D

So you'd need either

import java.awt.geom.Line2D;

or

import java.awt.geom.*;
Chris Thompson
  • 35,167
  • 12
  • 80
  • 109
3

Some lessons that should be learned from this:

  1. Star imports only import classes from a package. They do not import from sub-packages as well. In fact, sub-packages in Java are purely syntactic. As far as the Java language is concerned, there is NO semantic relationship between classes in different packages or sub-packages.

  2. Star imports tend to obscure problems. A lot of people recommend not using them. Write the imports out in full. Or better still, use an IDE that can do classname completion, and generate missing imports. (Granted, you do need to be a bit careful when for example the IDE offers you multiple completions for (say) Date or List.)

  3. Searching and reading the javadoc is a good way to help with problems like this. A javadoc search (or a class list scan) would tell you what the fully qualified name for the Line2D class is.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216