0

I have MixedComponent class that extends Applet And I have a NumericTextField class that i have made custom Textfield by extending TextField.

Now,

I have both of these classes in Same Package mypackage.

Now I am making an object of NumericTextField in MixedComponent, and it is giving me the error: Cannot find symbol: NumericTextField

NumericTextField myVar = new NumericTextField();

I want to use an object of type NumericTextField in MixedComponent How do i do that?

rjp
  • 13
  • 4
  • 1
    Obligatory "Applets are dead and modern browsers don't support them" comment. – Kayaman Aug 22 '18 at 08:49
  • Have you imported the `NumericTextField` class? – Kayaman Aug 22 '18 at 08:54
  • @Kayaman they are in same package so, i didn't import. – rjp Aug 22 '18 at 09:16
  • Well you have a compile time error. Check for typos and any other mistakes you've made. – Kayaman Aug 22 '18 at 09:20
  • No there isn't any typo error – rjp Aug 22 '18 at 09:34
  • Well are you compiling them correctly? How do you compile the files? – Kayaman Aug 22 '18 at 09:39
  • Since your custom classes are in the same package as the class where you want to use them and your custom classes have the same names as the applet classes you have to use the applet classes with their fully qualified names. Have a look at the question: [Importing two classes with same name. How to handle?](https://stackoverflow.com/questions/2079823/importing-two-classes-with-same-name-how-to-handle) – LuCio Aug 22 '18 at 10:02
  • @Kayaman Compile - javac ClassName.java – rjp Aug 22 '18 at 12:20
  • @LuCio both the classes have different name and are in same package – rjp Aug 22 '18 at 12:22
  • Have you compiled `NumericTextField` before trying to compile `MixedComponent`? – Kayaman Aug 22 '18 at 12:28
  • @Kayaman yess of course – rjp Aug 22 '18 at 12:41

1 Answers1

-1

NumericTextField is in your package, but it's not directly visible. You will need to either import it or reference it using its containing class.

e.g.

import mypackage.MixedComponent.NumericTextField;

NumericTextField myVar = new NumericTextField();

or

MixedComponent.NumericTextField myVar = new MixedComponent.NumericTextField();
killjoy
  • 3,665
  • 1
  • 19
  • 16
  • It is directly visible. It's in the same package. There's also no indication that `NumericTextField` is an inner class of `MixedComponent`, and if it were, the code would work just fine. – Kayaman Aug 22 '18 at 12:27