[android-developers] Re: What do these errors mean (using Eclipse)?
maybe you are right! On 2月1日, 下午5时23分, sourabh sahu souruit...@gmail.com wrote: I think you should write super(context) Sourabh On Wed, Feb 1, 2012 at 2:41 PM, atcal alan.williams...@ya.com wrote: I'm trying to define my own View subclass. public class myView extends View { myView(Context context) { View(context); } } 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 android documentation shows the constructor View(Context context) as public. Why can't I use it? -- 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- 隐藏被引用文字 - - 显示引用的文字 - -- 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
[android-developers] Re: What do these errors mean (using Eclipse)?
On Feb 1, 6:46 pm, Ted Scott t...@hootinholler.com wrote: On 2/1/2012 11:01 AM, atcal wrote: On Feb 1, 4:25 pm, Ted Scottt...@hootinholler.com wrote: On 2/1/2012 4:11 AM, atcal wrote: I'm trying to define my own View subclass. public class myView extends View { myView(Context context) { View(context); } } 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 android documentation shows the constructor View(Context context) as public. Why can't I use it? There are several reasons why View() is not available and will never be available. It means you don't understand class instantiation and the life cycle of a class. This is not an Android issue at all and I suggest that you spend some time learning Java fundamentals. These folks are generally pretty helpful with thathttp://www.javaranch.com/-Hide quoted text - - Show quoted text - Ted, Thanks. You are probably right. While I have 10 yrs experience of C++ with Windows and Java looks deceptively similar, things like this are tripping me up. I do understand about classes and instantiating objects but obviously not the peculiarities of Java. I've tried to register at javaranch but the website is not fast at sending back the registration activation email. I'll have to learn to be patient. I meant that they have tutorials and stuff. Since you have the syntax etc from c++ then maybe the O'Riely book Java in a Nutshell would be helpful. Oh, and you can forget the evil multiple inheritance and pointer stuff. ;) Probably a little tedious for you, but there is this:http://docs.oracle.com/javase/tutorial/java/javaOO/index.htmlwhich lacks a bit of detail as to why, but does cover the how of fundamentals.- Hide quoted text - - Show quoted text - Tom, I think I have to disagree with you when you say this is not an Android issue. I've just double checked the documentation and View is an Android class so my problems with it as an Android issue, not a Java issue. Can anyone answer my initial question? How do I subclass android.View? -- 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
[android-developers] Re: What do these errors mean (using Eclipse)?
On Feb 1, 10:23 am, sourabh sahu souruit...@gmail.com wrote: I think you should write super(context) Sourabh On Wed, Feb 1, 2012 at 2:41 PM, atcal alan.williams...@ya.com wrote: I'm trying to define my own View subclass. public class myView extends View { myView(Context context) { View(context); } } 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 android documentation shows the constructor View(Context context) as public. Why can't I use it? -- 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- Hide quoted text - - Show quoted text - Well, obviously I tried that but I just get the same error that there is no implicit constructor for View. -- 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
[android-developers] Re: What do these errors mean (using Eclipse)?
On Feb 1, 10:23 am, sourabh sahu souruit...@gmail.com wrote: I think you should write super(context) Sourabh On Wed, Feb 1, 2012 at 2:41 PM, atcal alan.williams...@ya.com wrote: I'm trying to define my own View subclass. public class myView extends View { myView(Context context) { View(context); } } 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 android documentation shows the constructor View(Context context) as public. Why can't I use it? -- 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- Hide quoted text - - Show quoted text - Sourabh, Sorry. Ignore my previous post. I was sure I'd tried that but I must have put super(). super(context) does work. Thanks. -- 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
Re: [android-developers] Re: What do these errors mean (using Eclipse)?
It's not an Android issue. It's not even a Java issue. The issue is: trying to use C++ syntax in Java. Inheritance is one of the things where Java is not quite the same as C++ (putting it mildly) - and the syntax differs too. I'd recommend spending a couple hours on a Java crash course, they can be easily found with Google Search. -- Kostya 02.02.2012 12:27, atcal пишет: my problems with it as an Android issue, not a Java issue -- Kostya Vasilyev -- 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
[android-developers] Re: What do these errors mean (using Eclipse)?
On Feb 2, 12:51 pm, Kostya Vasilyev kmans...@gmail.com wrote: It's not an Android issue. It's not even a Java issue. The issue is: trying to use C++ syntax in Java. Inheritance is one of the things where Java is not quite the same as C++ (putting it mildly) - and the syntax differs too. I'd recommend spending a couple hours on a Java crash course, they can be easily found with Google Search. -- Kostya 02.02.2012 12:27, atcal пишет: my problems with it as an Android issue, not a Java issue -- Kostya Vasilyev OK. So why is the documentation so misleading? View() is shown as a public method in teh android documentation. 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? ( super(context) passes the compiler but then crashes out at run time. Can anyone tell me the statement(s) I need to put in rather than refer me to a crash course. 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. ) -- 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
Re: [android-developers] Re: What do these errors mean (using Eclipse)?
On Thu, Feb 2, 2012 at 8:27 AM, atcal alan.williams...@ya.com wrote: OK. So why is the documentation so misleading? It is not misleading. It is following the same JavaDocs structure that has been used for a decade-plus for Java development. It is understood by hundreds of thousands of Java developers, including tens of thousands of Android developers. View() is shown as a public method in teh android documentation. No, it is not. It is listed in the Public Constructors section, not the Public Methods section. Are you seriously telling me that the explanation for this is that I don't understand Java inheritance? It would appear that you do not understand Java programming. I suggest that you spend time, outside of Android, learning Java programming, before returning to Android development. Here is a blog post of mine from a ways back outlining the key Java language bits that an Android developer would need to be comfortable with: http://commonsware.com/blog/2010/08/02/java-good-parts-version.html ( super(context) passes the compiler but then crashes out at run time. Use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine LogCat and look at the stack trace associated with your crash. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to *Advanced* Android Development_ Version 2.4 Available! -- 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
Re: [android-developers] Re: What do these errors mean (using Eclipse)?
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.htmlcontext) 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.htmlcontext,AttributeSet http://developer.android.com/reference/android/util/AttributeSet.htmlattrs) 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.htmlcontext,AttributeSet http://developer.android.com/reference/android/util/AttributeSet.htmlattrs, 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
[android-developers] Re: What do these errors mean (using Eclipse)?
On Feb 2, 3:41 pm, Kostya Vasilyev kmans...@gmail.com wrote: 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%28...(Context http://developer.android.com/reference/android/content/Context.htmlcontext) Simple constructor to use when creating a view from code. View http://developer.android.com/reference/android/view/View.html#View%28...(Context http://developer.android.com/reference/android/content/Context.htmlcontext,AttributeSet http://developer.android.com/reference/android/util/AttributeSet.htmlattrs) Constructor that is called when inflating a view from XML. View http://developer.android.com/reference/android/view/View.html#View%28...(Context http://developer.android.com/reference/android/content/Context.htmlcontext,AttributeSet http://developer.android.com/reference/android/util/AttributeSet.htmlattrs, 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/... 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 Kostya, Thanks for all this. I will follow up the links because I'm sure they will be useful for my next step. Just to put the record straight, I've resolved the problem I was having and it was nothing to do with a misunderstanding of Java - it was an android issue. My view subclass was being used in an activity subclass and the class loader was failing when my activity class tried to instantiate the view. When I added the activity to the xml manifest that error went away. I hadn't previously edited the manifest because I did not expect to intent the activity to create a separate thread at this stage of development and testing, but obviously that was a mistake. An android mistake. -- 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
Re: [android-developers] Re: What do these errors mean (using Eclipse)?
On 02/03/2012 02:34 AM, atcal wrote: Kostya, Thanks for all this. I will follow up the links because I'm sure they will be useful for my next step. You're wellcome. Just to put the record straight, I've resolved the problem I was having and it was nothing to do with a misunderstanding of Java Ok, my apologies if I was wrong. -- 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
[android-developers] Re: What do these errors mean (using Eclipse)?
On Feb 1, 4:25 pm, Ted Scott t...@hootinholler.com wrote: On 2/1/2012 4:11 AM, atcal wrote: I'm trying to define my own View subclass. public class myView extends View { myView(Context context) { View(context); } } 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 android documentation shows the constructor View(Context context) as public. Why can't I use it? There are several reasons why View() is not available and will never be available. It means you don't understand class instantiation and the life cycle of a class. This is not an Android issue at all and I suggest that you spend some time learning Java fundamentals. These folks are generally pretty helpful with thathttp://www.javaranch.com/- Hide quoted text - - Show quoted text - Ted, Thanks. You are probably right. While I have 10 yrs experience of C++ with Windows and Java looks deceptively similar, things like this are tripping me up. I do understand about classes and instantiating objects but obviously not the peculiarities of Java. I've tried to register at javaranch but the website is not fast at sending back the registration activation email. I'll have to learn to be patient. -- 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
Re: [android-developers] Re: What do these errors mean (using Eclipse)?
On 2/1/2012 11:01 AM, atcal wrote: On Feb 1, 4:25 pm, Ted Scottt...@hootinholler.com wrote: On 2/1/2012 4:11 AM, atcal wrote: I'm trying to define my own View subclass. public class myView extends View { myView(Context context) { View(context); } } 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 android documentation shows the constructor View(Context context) as public. Why can't I use it? There are several reasons why View() is not available and will never be available. It means you don't understand class instantiation and the life cycle of a class. This is not an Android issue at all and I suggest that you spend some time learning Java fundamentals. These folks are generally pretty helpful with thathttp://www.javaranch.com/- Hide quoted text - - Show quoted text - Ted, Thanks. You are probably right. While I have 10 yrs experience of C++ with Windows and Java looks deceptively similar, things like this are tripping me up. I do understand about classes and instantiating objects but obviously not the peculiarities of Java. I've tried to register at javaranch but the website is not fast at sending back the registration activation email. I'll have to learn to be patient. I meant that they have tutorials and stuff. Since you have the syntax etc from c++ then maybe the O'Riely book Java in a Nutshell would be helpful. Oh, and you can forget the evil multiple inheritance and pointer stuff. ;) Probably a little tedious for you, but there is this: http://docs.oracle.com/javase/tutorial/java/javaOO/index.html which lacks a bit of detail as to why, but does cover the how of fundamentals. -- 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