Reputation: 309
I am trying to cast my component to a custom Class name (OuterSpace) and it says I cannot do this. I am doing this in a class that inherits from JFrame.
//Add the game to the JFrame
add(new OuterSpace());
(OuterSpace)(getComponents()[0]).start();
It cannot be resolved however, even to any other class name. Here is the error-
OuterSpace cannot be resolved to a variable.
Upvotes: 2
Views: 852
Reputation: 285460
This looks wrong:
(OuterSpace)(getComponents()[0]).start();
It usually is done:
((OuterSpace)getComponents()[0]).start();
Having said this, regardless of what is right or wrong, this code looks like a fragile and dangerous kludge. If this were my project, I'd try to hold a more secure class-specific reference to my OuterSpace field, one that would not require casting, or require that my component be in a specific component array position.
Upvotes: 2