14
votes

Am new to programming with basic knowledge and I've taken a liken to Java.
I wanted to write a code that calculates a number to the nth power without using loops. I've been trying to use the repeat method from "commons lang" which i came to know about, about 4 days ago. I Found a lot of info in this site and others that helped me in understanding how to use this packed.
So far I downloaded commons-lang3-3.1 then kept the folder in the same folder as my project and added the jar file to my project's library by:-

right clicking on libraries
1 then Add JAR/Folder
2 then i opened the commons-lang3-3.1 folder
3 and selected "commons-lang3-3.1.jar" from a number of 4 selections:

  • commons-lang3-3.1.jar
    • commons-lang3-3.1-javadoc.jar
    • commons-lang3-3.1-sources.jar
    • commons-lang3-3.1-tests.jar

here is a code that am using to test that i got from one of the the other questions:-

0. package refreshingmemory;
1. import org.apache.commons.lang.StringUtils;
2. public class RefreshingMemory {
3.
4.     public static void main(String[] args) {
5.         String str = "abc";
6.         String repeated = StringUtils.repeat(str, 3);
7.         repeated.equals("abcabcabc");
8.
9.        }
10.    }

line 1 says package org.apache.commons.lang does not exist.
line 7 says Should check the method return value
and if i remove line 1 i get a cannot find symbol at line 6
How do I get a successfully import ?

Screenshot of Netbeans:

enter image description here

1
The line 6 error, is it a red (!) or a lightbulb+red(!) error? Sometimes netbeans will be nice and do the import for youRichard Tingle
yes it's a lightbulb+red(!) at line 6 but that disappears when i add the import at line 1. which means the package is detected. so i don't get why i keep getting that main error for the import.Mo Arctic
What happens when you click the lightbulb+red(!), does it offer to complete the import for you, does it autofill import org.apache.commons.lang.StringUtils; or is it (as predi suggests) slightly differentRichard Tingle
@RichardTingle: it probably didn't work for him at first, since he did not remove the erroneous import before attempting what you suggested.predi
It has saved my time in Intelij 2020.3 version.ArunDhwaj IIITH

1 Answers

29
votes

http://commons.apache.org/proper/commons-lang/ states the following:

Note that Lang 3.0 (and subsequent versions) use a different package (org.apache.commons.lang3) than the previous versions (org.apache.commons.lang), allowing it to be used at the same time as an earlier version.

So change the package accordingly, or heed Richard Tingle's advice and left click the error+light bulb icon in the gutter (were line numbers are shown) and choose "Add import for...".

import org.apache.commons.lang3.StringUtils;