aspose file tools*
The moose likes Beginning Java and the fly likes How do I subclass View? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I subclass View?" Watch "How do I subclass View?" New topic
Author

How do I subclass View?

Alan Key
Greenhorn

Joined: Feb 01, 2012
Posts: 2
I'm trying to define my own View subclass.




Eclipse flags the first line of my constructor with an error "Implicit
super conctructor View() is undefined. Must explicitly invoke another
constructor" and the second line is flagged with the error "The method
View(Context context) is undefined for the type myView."

What does all this mean? The java documentation shows the
constructor View(Context context) as public. Why can't I use it? What do I need to do
to make my own subclass fo View?

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4467
    
    8

Hi Alan. Welcome to The Ranch!

So you're trying to invoke the superclass constructor? The correct syntax is:
The version you have is looking for a method called View, and there isn't one (a constructor is not actually a method). That's the reason for the second error message. And because it doesn't recognise your attempt to call the superclass constructor, it tries to insert a call to the no-arg constructor - but that doesn't exist in View - which is what causes the first error message.
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 177
    
    6

You want instead of View(context).

The super keyword is used to reference the base class.

The compiler is implicitly doing this:


You will also want to capitalize your class "MyView" to comply with Java naming conventions. There is a code tag button for formatting your code nicely.


Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Alan Key
Greenhorn

Joined: Feb 01, 2012
Posts: 2
Tina Smith wrote:You want instead of View(context).

The super keyword is used to reference the base class.

The compiler is implicitly doing this:


You will also want to capitalize your class "MyView" to comply with Java naming conventions. There is a code tag button for formatting your code nicely.


Thanks Tina. I like the sound of a button for formatting my code nicely - I've been looking for one. Can you describe it? I'm trying to port a lot of C++ code from MS Visual Studio and I've found that the resulting code in Eclipse is not always tabbed nicely. Visual Studio has a hot key to re-tab code and I'd really like something equivalent.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
Tina was referring to code you copy into these forums. There is a Code button in the editor so that the code displays nicely in your posts (take a look at your original post now that Matthew has edited it).
If you want to format code in Eclipse try searching the help for Code Formatting or something similar.


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884
    
  28
Alan Key wrote:. . . I'm trying to port a lot of C++ code from MS Visual Studio and I've found that the resulting code in Eclipse is not always tabbed nicely. Visual Studio has a hot key to re-tab code and I'd really like something equivalent.
There are project-specific settings on Eclipse; you should set it to convert 1 tab to 4 spaces automatically. The problem you are experiencing may be caused by using tabs at all. You can re-indent on Eclipse with crtl-I. (I for India not L for Lima).
 
Don't get me started about those stupid light bulbs.
 
subject: How do I subclass View?