This question already has answers here:
Replacements for deprecated JPMS modules with Java EE APIs
(11 answers)
Closed 4 years ago.
I keep getting the NoClassDefFoundError error. I am trying to send an email using the JavaMail API, but the error occurs when I'm creating an instance of Message using the SMTPMessage class.
I know I need the activation library, but it still doesn't work.
By the way, I'm using JDK 10.
The error happens on the first line of this code.
#Override
public void sendEmail(Mail mail) throws MessagingException
{
Message message = new SMTPMessage(this.session);
message.setSubject(mail.getHeader());
message.setFrom(mail.getFrom());
message.setSentDate(mail.getDateClone());
if (mail.getSignature() != null)
message.setText(mail.getText() + "\n\n" + mail.getSignature());
else
message.setText(mail.getText());
Transport.send(message);
}
Stacktrace
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
at martin.mail.EmailHandler.sendEmail(EmailHandler.java:79)
at martin.Main.main(Main.java:22)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 2 more
Solution
Just add the activation library to your own class path. You can put it in your own package.
Related
This question already has answers here:
java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error using GeckoDriver Firefox through Selenium in Java
(1 answer)
Selenium Webdriver + Java - Eclipse: java.lang.NoClassDefFoundError
(7 answers)
Closed 2 years ago.
Hi i'm rather new to selenium and understand the basics but cant understand why my basic code it just open a web page is throwing the error its throwing. The error its throwing ill be listed at the bottom.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Selenium1 {
public static void main(String[] args) {
WebDriver Driver = new ChromeDriver ();
String web = "https://www.facebook.com/";
Driver.get(web);
System.out.println(Driver.getTitle());
}
}
Exception in thread "main" java.lang.NoClassDefFoundError:
com/google/common/collect/ImmutableMap at
org.openqa.selenium.remote.service.DriverService$Builder.(DriverService.java:259)
at
org.openqa.selenium.chrome.ChromeDriverService$Builder.(ChromeDriverService.java:101)
at
org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at Selenium1.main(Selenium1.java:10) Caused by:
java.lang.ClassNotFoundException:
com.google.common.collect.ImmutableMap at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more
basically cross from https://discuss.dev.twitch.tv/t/using-google-oauth-client-java-fails-to-execute-token-request/24191
the exception I get is this:
Exception in thread "main" java.lang.IllegalArgumentException: key scope
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:902)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:362)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:337)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:444)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:346)
at de.cryptearth.oauth.Main.main(Main.java:67)
Caused by: java.lang.IllegalArgumentException: key scope, field private java.lang.String com.google.api.client.auth.oauth2.TokenResponse.scope
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:902)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:453)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:789)
... 7 more
Caused by: java.lang.IllegalArgumentException: expected collection or array type but got class java.lang.String
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:164)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:67)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:726)
... 9 more
Any Idea what might could be the issue here?
Well, tried several OAuth libs linked on oaut.net but got none to work, so I ended up in doing it low-level with URLConnection and RegEx parsing.
Side-note: I also tried the other libs on YouTube, but only could Googles own implementation to work on it.
~closed
I'm writing a watson program to fetch personality traits. However, I'm running into errors with jar file issues.
import com.ibm.watson.developer_cloud.personality_insights.v3.PersonalityInsights;
import com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile;
public JSONArray getPersonalityTraitsFromWatson(String text) {
JSONArray retval = null;
PersonalityInsights service = new PersonalityInsights("2016-10-20", "xxxx", "yyyy");
Profile response = service.getProfile(text).execute();
System.out.println("profile: " + response);
return retval;
}
The first problem is with okhttp3. I get a classnotfound error with JavaNetCookieJar. I'm currently using okhttp3 and javanetcookiejar is missing in it. I picked up the okhttp3 from MVNRepository.
Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/JavaNetCookieJar
at com.ibm.watson.developer_cloud.service.WatsonService.configureHttpClient(WatsonService.java:137)
at com.ibm.watson.developer_cloud.service.WatsonService.<init>(WatsonService.java:117)
at com.ibm.watson.developer_cloud.personality_insights.v3.PersonalityInsights.<init>(PersonalityInsights.java:52)
at com.ibm.watson.developer_cloud.personality_insights.v3.PersonalityInsights.<init>(PersonalityInsights.java:70)
at com.xyz.social.Watson.getPersonalityTraitsFromWatson(Watson.java:20)
at com.xyz.Testing.UnitTester.startUnitTest(UnitTester.java:1720)
at com.xyz.Testing.UnitTester.main(UnitTester.java:1850)
Caused by: java.lang.ClassNotFoundException: okhttp3.JavaNetCookieJar
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I tried using "org.apache.servicemix.bundles.okhttp-3.2.0_1.jar" with and with the okhttp3.jar which clears the JavaNetCookieJar error but throws an SSLSocketFactory error (given below)
okhttp3.OkHttpClient$Builder.sslSocketFactory(Ljavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/X509TrustManager;)
Found the problem, the okhttp-urlconnection-3.8.1.jar & logging-interceptor-3.8.1.jar were required to be added. This fixed the problem.
This question already has answers here:
java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
(2 answers)
How to fix ClassNotFoundException: org.apache.commons.logging.LogFactory?
(5 answers)
Closed 6 years ago.
I am trying to send a notification using this class FCMHelper and im getting errors
errors leading me to an error in httpclient
this is my code ...
public void send() throws IOException{
JsonObject notificationObject = new JsonObject();
notificationObject.addProperty("data", "hello");
notificationObject.addProperty("to", "dSvX_cWo5iY:A......QQT-bkb8x0VO");
FireBase firebase = FireBase.getInstance();
firebase.sendNotification("to", "condition", notificationObject);
}
i got this error
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1783)
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1633)
... 58 more
what the problem here or if someone could give any other way to do it
.. thanks for your help
It seems "org/apache/commons/logging/LogFactory" is missed.
Have you imported the library?
This question already has an answer here:
How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?
(1 answer)
Closed 2 years ago.
I am working on a Javafx game and have been attempting to implement some sound using the following code:
URL laserResource = getClass().getResource("LaserBlast.wav");
AudioClip laserPlayer = new AudioClip(laserResource.toString());
This code is instantiated in the main class before any methods. I have a module called JavaFxImages which contains all my resources including my sounds and I have been successfully able to access images for ImageView from the folder through code such as Image asteroid = new Image("Asteroid.png");.
However, when I run my game I get a NullPointerException at the line for my audio clip. I have spent the past many hours researching and trying every different way to access this resource. I've tried many permutations of the URL ("JavaFxImages/LaserBlast.wav", Desktop/JavaFxImages/LaserBlast.wav", etc.), but every time it has the same error. I'm really at a loss for what is wrong with the code. I would greatly appreciate any help that can be given.
Thanks in advance!
The full error message is given below.
Error Message:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class sample.Main
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.NullPointerException
at sample.Main.<init>(Main.java:76)
... 10 more
Your error mostly happens on Itellij IDEA - Javafx Project
Instead of:
URL laserResource = getClass().getResource("LaserBlast.wav");
AudioClip laserPlayer = new AudioClip(laserResource.toString());
Use:
//By default your Package_NAME is: sample
File laserResource = new File("src/Package_NAME/LaserBlast.wav");
AudioClip laserPlayer = new AudioClip(laserResource.toURI().toString());