0

I currently have a Java program with a functioning Java class. I've created instances of that class manipulated them and printed them without any issues, however when I try to extend the class from the main method I get a symbol not found error.

public class Project3 extends StringInstrument{

The main class is Project3.java and the other class is StringInstrument.java so I'm not sure why netbeans knows where the StringInstrument.java file is to create and manipulate instances within it, but it cant find it to 'extend' it?

leigero
  • 3,233
  • 12
  • 42
  • 63
  • 1
    It looks fine - the problem is not in the code you show. – assylias Oct 14 '12 at 16:31
  • have tried you importing `StringInstrument` class? – Abubakkar Oct 14 '12 at 16:32
  • Java jas strict requirements on files location. Each file should be located in the directory which name is corresponding with file's package directive. To find class, Java needs file be either in the same package (directory) or located with the help of `import` directive. – Suzan Cioc Oct 14 '12 at 16:36

1 Answers1

1

My guess is you need to find the package where StringInstrument.java is. And import it.

import stringInstrumentPackage.StringInstrument;
Lews Therin
  • 10,907
  • 4
  • 48
  • 72
  • They're both inside the same package. Would I need to import it if they're both in it? Its package: project3 inside that you have Project3 with main class and StringInstrument – leigero Oct 14 '12 at 16:36
  • GAH! My code is crazy complicated so to avoid it I was going to write a smaller version and in doing so found my problem. The file name is StringInstrument.java but the CLASS I was trying to extend on WITHIN that file is Class Violin() – leigero Oct 14 '12 at 16:42
  • @leigero: Do you have the package declarations same in both the classes? – Bhesh Gurung Oct 14 '12 at 16:43
  • @leigero So Violin is a nested class of StringInstrument? – Lews Therin Oct 14 '12 at 16:44
  • yes, the StringInstrument.java file was going to have several classes, but it only has the one Violin class. I was trying to 'extend' the entire StringInstrument file i guess rather than the Violin class within it – leigero Oct 14 '12 at 16:47
  • Mmn, don't think that should make a difference. But the best would be to separate the instruments in their own .java file. And you can have them in an instruments package if you like. – Lews Therin Oct 14 '12 at 16:49