• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with error " The method length() is undefined "  RSS feed

 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am practicing using CodingBat.com
http://codingbat.com/prob/p163411

I'm receiving the error that the length() method is undefined.  When I put it in Eclipse this works fine so I'm not sure why it's not working on CodingBat.com. 



But this works in Eclipse



 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think It suppose to be I don't know what exactly you want to do but did you notice what happens when String str = "A"; Or str = ""; ?
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh Patekar wrote:I think It suppose to be I don't know what exactly you want to do but did you notice what happens when String str = "A"; Or str = ""; ?


I wasn't clear in my message.  The problem currently being flagged is just the length() in .  So I took it to Eclipse to try and it works fine.   It prints out "He".
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes second example will work for sure, I was talking about first example which has else part.
 
Liutauras Vilda
Marshal
Posts: 4651
319
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it was mentioned already, that problem is in line 9
in between the parenthesis you forgot to add references on which you're calling length() methods.
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay guys!  Thank you. 
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a neat site, never saw it before.

The ternary operator is my sonic screwdriver:
 
Liutauras Vilda
Marshal
Posts: 4651
319
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And need to consider checking if str isn't null before you invoke length() method or ensure outside the method that passed str isn't null and handle it appropriately otherwise.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!