This question already has answers here:
How to solve this java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream?
(6 answers)
Closed 6 years ago.
I'm using IntelliJ and I am trying to use the FileUtils.copyFile() method. When I use that method I get this error:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apach
e/commons/io/FileUtils
Here is the code that uses the copy file method:
import org.apache.commons.io.FileUtils;
...
try {
File destJAR = new File("c:/X-Dock/MP3Player.jar");
File playerJAR = new File(MP3Player); //"MP3Player" is a string that is defined earlier.
FileUtils.copyFile(playerJAR, destJAR);
}catch (IOException e){
e.printStackTrace();
}
I imported the Apache Commons JAR "commons-io-2.4" into the IntelliJ project by going to
File -> Project Structure -> Libraries -> Add -> Java -> "commons-io-2.4.jar"
Any help would be greatly appreciated.
Follow these steps to resolve your problem.
or you can edit configuration file
build.gradle
dependencies {
compile files('libs/commons-io-2.4.jar')
}
Related
This question already has answers here:
Java - mkdir() not writing directory
(2 answers)
Closed 4 years ago.
I used new File(directory).mkdir() to create a new folder.
When i setdirectory = "C:\\Users\\livw\\Desktop\New folder\\5b27233480c016706f62a30a",
it works.
But when i add one more child folder to the directory: directory = "C:\\Users\\livw\\Desktop\\New folder\\5b27233480c016706f62a30a\\Samples",it doesn't create the folder.
How can i fix it?
Short and sweet,
Use mkdirs() instead of mkdir().
Hope it helps
Please in future refer to documentation.
directory = "C:\Users\livw\Desktop\New folder\5b27233480c016706f62a30a"
kindly check the directory address as file separator is not properly given before new Folder
import java.io.File;`
public class FileCreation {
public static void main(String[] args) {
new File("C:\\Users\\Master\\Desktop\\Horse\\demo\\devil").mkdir();
new File("C:\\Users\\Master\\Desktop\\Horse\\demo\\devil"+File.separator+"a").mkdir();
}
}
This question already has answers here:
java.lang.NoClassDefFoundError when using MongoDB driver
(3 answers)
Closed 5 years ago.
I have simple java program that tries to connect to my only mongodb local instance and I want to insert some data. I have these referenced jar files when running the code:
- C:\Users\olgad\Downloads\jsoup-1.11.2.jar
- C:\Users\olgad\Downloads\mongodb-driver-3.6.1.jar
- C:\Users\olgad\Downloads\bson-3.0.4.jar
- C:\Users\olgad\Downloads\java-json.jar\java-json.jar
- C:\Users\olgad\Downloads\mongo-java-driver-2.9.1.jar\mongo-java-driver-2.9.1.jar
- C:\Users\olgad\Downloads\mongodb-driver-core-3.0.1.jar
My mongodb version is 3.4.10
public class Main {
public static void main(String[] args) throws IOException {
try {
MongoClient mongoClient = new MongoClient("localhost",27017);
DB database = (DB) mongoClient.getDatabase("test");
DBCollection collection = database.getCollection("myCol");
DBObject dbObject = (BasicDBObject) JSONObject.stringToValue("{'name':'mkyong', 'age':30}");
collection.insert(dbObject);
} catch(Exception ex) {
// Prints what exception has been thrown
System.out.println(ex.getMessage());
}
}
}
The error that is printed is:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBRefCodecProvider at
com.mongodb.MongoClient.(MongoClient.java:89) at
prvCrawler.Main.main(Main.java:30)
Thanks in advance! Olga
You have one too many jars with conflicting packages. Remove all the mongodb related jars first and start over.
You have two options:
Manually downloading the jar ( Use one of the below option ). Use same versions for all jars.
Download the mongo-java-driver uber jar which contains all the necessary libraries packaged as one.
Download the jars (mongodb-driver, mongodb-driver-core, and bson) individually.
Use Maven/Gradle for downloading the jars.
This question already has answers here:
javax.* cannot be imported in my Android app?
(5 answers)
Closed 7 years ago.
I am facing problem with some packages like Javax, when i am trying to import the following packages in my android applications!
Javax.naming.Naming.Exception;
Javax.naming.directory.DirContext;
Javax.naming.directory.InitialDirContext;
private DirContext connectLDAP()
throws NamingException
{
Properties localProperties = new Properties();
localProperties.setProperty("java.naming.factory.initial", LDAP_PROVIDER);
localProperties.setProperty("java.naming.batchsize", "0");
localProperties.setProperty("java.naming.provider.url", this.params.getLdapURL());
localProperties.setProperty("java.naming.factory.url.pkgs", "com.sun.jndi.url");
localProperties.setProperty("java.naming.referral", REFERRALS_IGNORE);
localProperties.setProperty("java.naming.security.authentication", "none");
return new InitialDirContext(localProperties);
}
help me to resolve this problem.
The classes that you are trying to use are not part of the Android SDK. You will need to find some other solution for whatever problem it is that you are trying to solve.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to use .dll files in java code?
The dll file, I am using, is giving error:
The error message is:
java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: Eagleye_parser
at java.lang.Runtime.load0(Runtime.java:767)
at java.lang.System.load(System.java:1005)
at test.TestDllJava.<clinit>(TestDllJava.java:15)
Exception in thread "main"
This is the code:
public class TestDllJava {
private static native String[] eagleye_fmu(String A);
public static void main(String[] args){
String[] ag = null;
String parameter = null;
parameter = "356188030442449 10250000 0001F464 0000EB34 0002CC7D 4xA0";
ag = eagleye_fmu(parameter);
System.out.println(ag);
}
static {
System.load("Eagleye_parser");
}
}
Please correct me, where I am doing wrong.
As the docs of load() specify:
Loads a code file with the specified filename from the local file
system as a dynamic library. The filename argument must be a complete
path name.
A better approach without stating an absolute path to library is by using loadLibrary() or maybe load(mapLibraryName(..)).
In Eclipse, you can specify native library folder in your project via project Properties -> Java build Path -> tab Libraries -> expand your System Library, click Native Library Location. Eclipse will build java.library.path for you and loadLibrary() will then see it easily.
This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Closed 10 years ago.
I'm developing an android apps with Eclipse.
In my app, I try to read a file : data.xml. I put it in res/raw/, and to access it i'm supposed to use getRessources().openRawResource(R.raw.data);
But Eclipse show me an error : "data" cannot be resolved or is not a field.
But the field is in the gen/R.java !!!
public final class R {
public static final class raw {
public static final int data=0x7f040000;
}
}
Any ideas ?
Thanks
Solution :
Import the right R.java files !
import my_package.R;
Stop trusting ctrl+shift+O ...
I already faced this problem several weeks ago. You simply have to use com.example.R (where com.example is the name of your package), because your IDE thinks that you are using android.R by default.
Try this out.
Try to clean and rebuild your project!
Or just delete import android.R;.
If that data.xml is in raw folder but still its not resolved once Clean and build your project and check.
Still error check this : Opening raw file