On 02/02/2012 05:27 PM, atcal wrote:
OK. So why is the documentation so misleading? View() is shown as a
public method in teh android documentation.

Not for me:

http://developer.android.com/reference/android/view/View.html

Public Constructors
View <http://developer.android.com/reference/android/view/View.html#View%28android.content.Context%29>(Context <http://developer.android.com/reference/android/content/Context.html>context)
Simple constructor to use when creating a view from code.
View <http://developer.android.com/reference/android/view/View.html#View%28android.content.Context,%20android.util.AttributeSet%29>(Context <http://developer.android.com/reference/android/content/Context.html>context,AttributeSet <http://developer.android.com/reference/android/util/AttributeSet.html>attrs)
Constructor that is called when inflating a view from XML.
View <http://developer.android.com/reference/android/view/View.html#View%28android.content.Context,%20android.util.AttributeSet,%20int%29>(Context <http://developer.android.com/reference/android/content/Context.html>context,AttributeSet <http://developer.android.com/reference/android/util/AttributeSet.html>attrs, int defStyle)
Perform inflation from XML and apply a class-specific base style.


I don't see an argument-less View() here.

There is an argument-less constructor in the source:

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/View.java#L3127

but it's access level is package, not public or protected, so application code won't be able to use it.


Why is it not available to
a subclass? Are you seriously telling me that the explanation for this
is that I don't understand Java inheritance?

I'm seriously telling you that the snippet in your original email looked like you used C++ constructor syntax, or something similar, and not Java syntax.



(  super(context) passes the compiler but then crashes out at run
time.

If you're trying to create a custom view, please refer to this:

http://developer.android.com/guide/topics/ui/custom-components.html

In particular, it says:

There is a form of the constructor that are called when the view is created from code and a form that is called when the view is inflated from a layout file. The second form should parse and apply any attributes defined in the layout file.

The former is YourView(Context), the latter is YourView(Context, AttributeSet)

Can anyone tell me the statement(s) I need to put in rather than
refer me to a crash course.

The link above should be a good start.

I've already spent several hours reading
the Oracle java course, so unless you have a specific course and
chapter in mind the suggestion isn't very helpful. )

I'll just put it here then:

The syntax for calling the base class constructor from a derived class constructor, in Java, is:

class Derived extends Base {

    public Derived(.. args here...)
    {
        super(... args here....);
    }
}

and not:

class Derived extends Base {

    public Derived(.. args here...)
    {
        Base(... args here....);
    }
}

or:

class Derived extends Base {

    public Derived(.. args here...) : Base (... args here... )
    {
    }
}


Why is this? Java doesn't have MI like C++, so it's not necessary to explicitly specify which of the base classes you're referring to - just "super" is unambiguous.

And actually, in C++, your original code snippet would be creating a temporary View object on the stack, rather than initializing the base class.

-- Kostya

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to