• Post Reply Bookmark Topic Watch Topic
  • New Topic

error on .lenght method  RSS feed

 
Alessio Conte
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi im trying to run the following code but i get an error on the method .lenght. Can you help me please???

public class Prova{
public static void main (String [] args){
String[] dog  = {"Gringo" , "Fido" , "Cesare"}; 
int x = dog.lenght ;
System.out.println(x);
}

}
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Java arrays do not have a lenght() method, or a lenght instance variable / field.  Perhaps, you meant the length field? Note the spelling.

Henry
 
Alessio Conte
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Java arrays do not have a lenght() method, or a lenght instance variable / field.  Perhaps, you meant the length field? Note the spelling.

Henry


Yer Pheraps. Anyway it does not run ....do you know way ?? Thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alessio Conte wrote:
Yer Pheraps. Anyway it does not run ....do you know way ?? Thanks


It doesn't run because it doesn't compile. And it doesn't compile because there isn't a lenght field. Spelling (and case) is important. The compiler doesn't assume or guess your intentions.

BTW, are you purposely adding lots of misspellings in your response? ...

Henry
 
Alessio Conte
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Alessio Conte wrote:
Yer Pheraps. Anyway it does not run ....do you know way ?? Thanks


It doesn't run because it doesn't compile. And it doesn't compile because there isn't a lenght field. Spelling (and case) is important. The compiler doesn't assume or guess your intentions.

BTW, are you purposely adding lots of misspellings in your response? ...

Henry


Sorry I have just noticed my error..thanks a lot  😁😁😁....
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Maybe if you don't speak English all the time, you might find an IDE useful for such things. Copy and paste your entire code to an IDE e.g. Eclipse; it will give you suggestions about how to correct such errors, including
Eclipse wrote:Change to ‘length'
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!