• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I subclass View?

 
Alan Key
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alan Key
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic