开发者

ArrayUtil causes unexpected error in Java

Whenever I write a code that includes an ArrayUtil, it causes an unexpected error:

int[] values 开发者_开发问答= ArrayUtil.randomIntArray(30, 300);

I use Eclipse to write my code, and there is always a red underline under "ArrayUtil". What am I doing wrong?


A couple things to help you, when you see the red squiggly lines in Eclipse:

  • Read the tool tip in the sidebar (on the left hand side of the editor pane). It gives you enough information about the problem. It might point out a missing import (in your case), but the problem might not end there.
  • Use Ctrl + 1 shortcut to determine if Eclipse can provide a resolution to this problem. Eclipse will import the required class, if you tell it do so; there will be no need to key in the missing import.
  • If you are seeing too many errors, use the Problems or Errors view to know about all the problems.

Now, if all of the above have not helped you, it might be because ArrayUtil as a class is not recognized by Eclipse in your environment. Maybe you meant the ArrayUtils class of Apache Commons Lang. Or maybe you meant a custom ArrayUtil class that you wrote.

If it's first, Eclipse can perform the auto-import only if Commons-Lang is in a library. If it's the second, then auto-import will add the necessary project to your build path (if it is necessary, the class is in a different project), and also import it. But before that, you'll need to know what ArrayUtil are you intending to import.


What package does your ArrayUtil belong to? No one can answer with certainty without that information.

Did you get it here? If yes, your signature looks right. You probably haven't imported it yet, or the class isn't in your CLASSPATH. Eclipse is telling you to correct one or the other.


Eclipse is trying to tell you it can't resolve the ArrayUtil class. Do you have an import statement for it?


There's no class by that name in the standard Java APIs, and Eclipse is presumably telling you this. There's on in Java EE 5, and there's an "ArrayUtils", with an "s", in Apache commons, maybe you want one of those? In which case you'd have to import it, and include the jar files in your project.


I realised you are using the ArrayUtil.randomIntArray(30, 300);

Custom build class, you need to have the corresponding jar files or the classess which have those methods.

When i see closely i think you are trying to genarate the random Numbers, if yes why dont you consider the java builtin classes in util package like following url

http://java.about.com/od/javautil/a/randomnumbers.htm

http://www.javapractices.com/topic/TopicAction.do?Id=62

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜