Java cannot find symbol compilation error
new to Java. I want to use the org.apache.commons.lang.WordUtils package. Tried importing it. Tried downloading it and adding it to my build path. When I use word intellisense WordUtils
, Eclipse automatically puts an import statement at the beginning of the file.
I am getting the following error when compiling:
ConvertToUrl.java:3: package org.apache.commons.lang import org.apache.commons.lang.WordUtils; ^ ConvertToUrl.java:36: cannot find symbol symbol: variable WordUtils location: class d6.common.ConvertToUrl url = WordUtils.capitalizeFully (url); ^ 2 errors
And when I remove the import statement at the top, I get:
ConvertToUrl.java:34: cannot find symbol symbol: variable WordUtils location: class d6.common.ConvertToUrl url = WordUtils.capitalizeFully (url); ^ 1 error
thank
Go to your project properties and in the Java Build Path (I think) you need to add the commons banner as an external Jar, it's pretty straight forward, once you find the tab you want in the properties, once you can view where you downloaded the jar and add it which should fix your problem.
source to share
Thanks everyone. The class is in the build path.
I pasted in the class I am using below (minus the unnecessary bits).
As I said, Eclipse adds an import statement to this.
import org.apache.commons.lang.WordUtils;
Do I still need this if I downloaded the JAR?
btw: I didn't choose classpath 101, I just get the way I go, brand new to Java.
package d6.common;
public class ConvertToUrl {
private static String url;
public String getUrl() {
return url;
}
public void setUrl(String url) {
url = WordUtils.capitalizeFully(url);
this.url = url;
}
}
Thanks for the help!
When you get a compiler error, where are you doing this from? Is this when you try to compile the source on the command line? If so, then you need to make sure the jar is either set in your CLASSPATH variable, used on the command line, added to your build.xml file, or set to whatever mechanism you use to compile the class.
source to share
If you are using ant script to build your code in eclipse check if classpath is specified in build.xml file. You can use something like this in the javac tag in your build file. Where pathelement here is the dependent library:
<target name="compile" depends="init" description="compile the source " >
<javac srcdir="${src}" destdir="${classsfiles}" >
<classpath>
<pathelement path="${libdir}/common-io.jar"/>
<pathelement path="${libdir}/xerces.jar"/>
</classpath>
</javac>
</target>
source to share
You will never need to use one import. All you need to do is save the text: you can type "WordUtils" instead of "org.apache.commons.lang.WordUtils" whenever you want to use the class.
If you still have a problem, it says that the class is NOT in the build path and you still need to figure out how to get it.
source to share