Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I added import java.util.ArrayList; (per suggestions here) to my code and then I got 2 different kinds of errors. They are:

error: the type of the expression must be an array type but it resolved to java.util.ArrayList<java.lang.Integer>

and:

error: length cannot be resolved or is not a field.

Can anyone tell me what they mean? I've tried changing the length statements by adding () at the end but that cause more errors then I started with.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
194 views
Welcome To Ask or Share your Answers For Others

1 Answer

For an ArrayList you need to call the .size() Method to get the number of elements, not length. You can't just treat the ArrayList like a basic array. Please provide some code samples for help with the other error.

int i = myList.size();

EDIT:

I've just seen, that someone actually mentioned that already in another question of yours. How to modify a java program from arrays to arraylist objects?

Since you try to employ a method of community-coding just some tips for you to grow and the community to save some nerves ;)

Try to keep the JavaDoc open in a browser while you code: http://download.oracle.com/javase/6/docs/api/

If you want to experiment with an ArrayList, look up which methods and properties it has. Usually, it also links to proper tutorials like, e.g. how to use collection classes. It's probably quicker to browse the JavaDoc rather than posting a question here and it will give you a good general picture of basic Java classes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...