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.
Related
This question already has answers here:
Why am I getting a NoClassDefFoundError in Java?
(31 answers)
Closed 2 years ago.
package com.sm.mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.types.ObjectId;
public class JavaMongoConnection {
public static void main(String[] args) {
//System.setProperty("jdk.tls.trustNameService", "true");
MongoClientURI uri = new MongoClientURI(
"mongodb+srv://admin:admin123#cluster0-bkruu.mongodb.net/test?retryWrites=true&w=majority");
MongoClient mongoClient = new MongoClient(uri);
MongoDatabase database = mongoClient.getDatabase("test");
}
}
This is my code, and whenever I run this code, I get the error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/MongoClientURI
I looked at java.lang.NoClassDefFoundError when using MongoDB driver and I tried their solution where I went to Run Configurations --> Dependencies and looked under Classpath Entries to make sure that I have bson-xxx.jar, mongodb-driver-xxx.jar, and mongodb-driver-core-xxx.jar listed. I have these listed and despite this, I keep getting the same error as in that stackoverflow post.
Any help would be appreciated.
com/mongodb/MongoClientURI class is present in mongo-java-driver jar. https://mongodb.github.io/mongo-java-driver/
Including the above jar in classpath should fix the issue
This question already has answers here:
java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests
(5 answers)
Closed 4 years ago.
I am currently having a bad first time experience of using this forum, with my questions being repeatedly deleted as duplicates despite my explaining that the suggested fixes are not solving my problem. The cause of the first questioner’s error was incorrect jars, I appear to have the correct ones according to the list proposed in that thread.
This is my code:
package sanityTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "/Users/lawrencedonohoe/Downloads/geckodriver");
WebDriver driver = new FirefoxDriver();
}
}
I am getting the following error:
Unresolved compilation problem: WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type
I gather from other forum articles that this is due to not having the correct jars in my build path, or having one I shouldn't. I appear, however, to have all the jar files the aforementioned question's answerers suggest I need.
This a full list of the jars I have added:
client-combined-3.14.0-sources
client-combined-3.14.0
byte-buddy-1.8.15
commons-codec-1.10
commons-exec-1.3
commons-logging-1.2
guava-25.0-jre
httpclient-4.5.5
httpcore-4.4.9
okhttp-3.10.0
okio-1.14.1
Can someone please help me?
Please try following code, it is defining driver path manually and also If you are using linux environment, it can be related with permissions to read the drivers path :
System.setProperty("webdriver.gecko.driver","pathToYourDriver/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
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:
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')
}
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