java中的java错误 [英] java errors in dr java

查看:369
本文介绍了java中的java错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了 import java.util.ArrayList; 每个建议在这里)到我的代码,然后我有2种不同类型的错误。它们是:

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>

和:

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.

推荐答案

对于ArrayList,您需要调用.size()方法来获取元素的数量,而不是长度。你不能像一个基本的数组一样对待ArrayList。请提供一些代码示例,以帮助解决其他错误。

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();

编辑:

看到,有人实际上提到了已经在你的另一个问题。
如何修改java程序从数组到数组列表对象?

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 ;)

尝试在浏览器中打开JavaDoc,代码如下: http://download.oracle.com/javase/6/docs/api/

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

如果您想实验一个ArrayList,查找它有哪些方法和属性。通常,它还链接到正确的教程,例如,如何使用集合类。
这可能是更快的浏览JavaDoc,而不是在这里发布一个问题,它会给你一个很好的基本Java类的一个很好的概述。

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.

这篇关于java中的java错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆