2

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?

0

5 Answers 5

7

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.

Sign up to request clarification or add additional context in comments.

4 Comments

this should be a comment, not a reply
I think it's a perfectly good answer. It addresses the longer-term goal of learning how to use Eclipse. What gives with all these "reply versus comment" police? I think this answer is more helpful than this useless pseudo-moderation.
Ah well, I tried to incorporate both your comments into the edit.
Agreed 110% with duffymo. The surface problem is that John's compiler error (which he doesn't tell us enough to diagnose). The much larger problem is not knowing how to use the tools in front of him which tell him exactly what is wrong and how to fix it. Fix that, and you fix #1 and a thousand other problems.
0

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.

4 Comments

Came from some guy's book. Fixed. Why do you care? I can think of better ways to boost your 992 rep. Stop trolling old links and answer some questions.
I came across this answer to find a solution to one my problem. Looks you've mind it, I never intended that. BTW, try to be patient and do not get offended so quickly.
I've seen too many users who make a career out of trolling old questions. Perhaps that's not you.
I don't even know what are you talking about. I wouldn't care. Since you are still fixated at trolling, l can only appreciate your attitude of judging others :)
0

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

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.