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?
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.
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
posted
0
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: 3011
9
posted
0
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: 32654
4
posted
0
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).