I wanted to test the GeocodingAPI-example of the googles hompage (the code).
I'm working with Java in eclipse and I already added the library "google-maps-services 0.1.7" to my project. This is my code:
package test;
import com.google.maps.*;
import com.google.maps.model.GeocodingResult;
public class Distance {
public static void main(String[] args) throws Exception {
GeoApiContext context = new GeoApiContext().setApiKey("AIza...");
GeocodingResult[] results = GeocodingApi.geocode(context,
"1600 Amphitheatre Parkway Mountain View, CA 94043").await();
System.out.println(results[0].formattedAddress);
}
}
When I want to run the code, the following problem is shown in the console:
Exception in thread "main" java.lang.NoClassDefFoundError: com/squareup/okhttp/OkHttpClient
at com.google.maps.GeoApiContext.<init>(GeoApiContext.java:50)
at test.Distance.main(Distance.java:10)
Caused by: java.lang.ClassNotFoundException: com.squareup.okhttp.OkHttpClient
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)
... 2 more
I changed the API to my personal API. What is wrong in this code? Are there mistakes in the import-instructions?
Related
Hello First time posting so sorry if this is bad
I keep running into this error code, I have tried reinstalling different versions of JDA and the only one that works is JDA-4.3.0_333, I am using eclipse. I even reinstalled eclipse to the for developers version. I have restarded and rewritten multiple times runnning into the same error
Exception in thread "main" java.lang.NoClassDefFoundError: net/dv8tion/jda/api/JDABuilder
at threeStringsMusicBot.StartUp.main(StartUp.java:11)
Caused by: java.lang.ClassNotFoundException: net.dv8tion.jda.api.JDABuilder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
package threeStringsMusicBot;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
public class StartUp {
public static void main(String[] args) throws LoginException{ //Login Exception allows for bot to log into bot account'
JDABuilder threeStrings = JDABuilder.createDefault("#######"); //create new bot with JDABuilder class and give it our bot token
threeStrings.setActivity(Activity.playing("The Lute!")); //set bot activity
threeStrings.setStatus(OnlineStatus.ONLINE); //set bit status to online
threeStrings.build(); //build(); function calls for bot to login
}
}
needed to be on JAVA 1.8, I was previously on the current version of java but this version of JDA needed java 1.8.
I am trying to export customized values metrics of my Java application to Prometheus. I have read that it could be done with Push Gateway, following an example I use the next method:
static void executeBatchJob() throws Exception {
CollectorRegistry registry = new CollectorRegistry();
Gauge duration = Gauge.build()
.name("my_batch_job_duration_seconds").help("Duration of my batch job in seconds.").register(registry);
Gauge.Timer durationTimer = duration.startTimer();
try {
// Your code here.
myCode();
// This is only added to the registry after success,
// so that a previous success in the Pushgateway isn't overwritten on failure.
Gauge lastSuccess = Gauge.build()
.name("my_batch_job_last_success").help("Last time my batch job succeeded, in unixtime.").register(registry);
lastSuccess.setToCurrentTime();
} finally {
durationTimer.setDuration();
PushGateway pg = new PushGateway("172.16.124.40:9091");
pg.pushAdd(registry, "my_batch_job");
}
}
But when I run the project I am having the next error:
Exception in thread "main" java.lang.NoClassDefFoundError: io/prometheus/client/exporter/common/TextFormat
at io.prometheus.client.exporter.PushGateway.doRequest(PushGateway.java:299)
at io.prometheus.client.exporter.PushGateway.pushAdd(PushGateway.java:158)
at nemshelloworld.NemsHelloWorld.executeBatchJob2(NemsHelloWorld.java:78)
at nemshelloworld.NemsHelloWorld.main(NemsHelloWorld.java:33)
Caused by: java.lang.ClassNotFoundException: io.prometheus.client.exporter.common.TextFormat
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
You're missing the simpleclient_common module, which is a listed dependency of simpleclient_pushgateway so it sounds like your pom.xml or equivalent isn't right.
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.
I'm trying to use the HotSwap feature of byte buddy. Unfortunately I receive some errors. I have read the documentation on the official website, and I'm aware that it only works when the program use a Java agent. I have tried to put -javaagent parameter on the startup of the Java virtual machine which looks like this:
-javaagent:C:\lib\byte-buddy-agent-0.5.6.jar
This produces the following error when starting my application:
java.lang.ClassNotFoundException:
net.bytebuddy.agent.ByteBuddyAgent.Installer
FATAL ERROR in native method: processing of -javaagent failed
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) at
sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:304)
at
sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Exception in thread "main" Java Result: 1
Nevertheless I tried use the ByteBuddyAgent.installOnOpenJDK() method instead of the -javaagent parameter in hope that will solve the problem. But this throws following error, which relies on the same problem I think:
java.lang.ClassNotFoundException: net.bytebuddy.agent.ByteBuddyAgent$Installer
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)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:304)
at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:411)
Apr 09, 2015 1:35:01 PM net.bytebuddy.agent.ByteBuddyAgent doInstall
INFORMATION: Cannot delete temporary file: C:\Users\Flo\AppData\Local\Temp\byteBuddyAgent4745240427430305215.jar
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1770)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1653)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
...
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
...
Caused by: java.lang.IllegalStateException: The programmatic installation of the Byte Buddy agent is only possible on the OpenJDK and JDKs with a compatible 'tools.jar'
at net.bytebuddy.agent.ByteBuddyAgent.installOnOpenJDK(ByteBuddyAgent.java:176)
at hotswapping.FXMLDocumentController.handleByteBuddyButton(FXMLDocumentController.java:90)
... 60 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.bytebuddy.agent.ByteBuddyAgent.doInstall(ByteBuddyAgent.java:199)
at net.bytebuddy.agent.ByteBuddyAgent.installOnOpenJDK(ByteBuddyAgent.java:174)
... 61 more
Caused by: com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:121)
... 67 more
Does anyone know what is the problem or have I misunderstood something from the tutorial? Btw I tried it with jdk1.7.0_55 and jdk1.8.0_40 and use neatbeans as ide. Version of byte buddy which I am using is v0.5.6.
Thanks for helping.
EDIT:
It seems that the error with the -javaagent parameter is a bug in the current version, thanks Rafael Winterhalter for the quick response.
I also figured out what was problem with the ByteBuddyAgent.installOnOpenJDK() method. It was a really stupid mistake from my side. It seems my netbeans use an older java version as jdk1.8.0_40, so I changed the netbeans_jdkhome variable in the netbeans.conf file in the etc folder of netbeans. Now that my netbeans use the same java version as my projects it seems that it works like a charm even with JavaFX applications. The only strange thing is that this error occurred only in JavaFX applications, in normal Java applications I never had this problems. FYI: Here is the code sample of my JavaFX application:
package testbytebuddy;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import net.bytebuddy.agent.ByteBuddyAgent;
public class TestByteBuddy extends Application {
#Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Start application");
ByteBuddyAgent.installOnOpenJDK();
launch(args);
System.out.println("End application");
}
}
The problem with using the agent directly is a bug in Byte Buddy where I reference the agent's main class with net.bytebuddy.agent.ByteBuddyAgent.Installer and not with net.bytebuddy.agent.ByteBuddyAgent$Installer as it would be correct. This will be fixed for Byte Buddy 0.5.7 which should be released at the end of April / beginning of Mai.
For the second error, it seems like you used a bundled JDK that does not allow the programmatic attachment of the agent. It was difficult to see as this resultet in a similar error message. The programmatic attachment is however something that can go wrong, therefore it is difficult to provide more detailed information on the actual cause. Good you figured it out.
This answer was already solved in the comments, this should serve as an overview for potential future readers.
This is my first time using the Gmail REST API and I'm trying to send an email using it. I followed the instructions on Google Developer site and got the authentication part successful. But now when I'm trying to send a email an Exception is thrown. Complete exception is,
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
at javax.mail.Session.initLogger(Session.java:227)
at javax.mail.Session.<init>(Session.java:212)
at javax.mail.Session.getDefaultInstance(Session.java:315)
at gmailconsole.Email.createEmail(Email.java:45)
at gmailconsole.GmailApiQuickStart.main(GmailApiQuickStart.java:91)
Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.MailLogger
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
The code that associated with the exception
public static void sendMessage(Gmail service, String userId, MimeMessage email)
throws MessagingException, IOException {
Message message = createMessageWithEmail(email);
message = service.users().messages().send(userId, message).execute();
System.out.println("Message id: " + message.getId());
System.out.println(message.toPrettyString());
}
Method call in the main class
try {
MimeMessage mimeMessage = Email.createEmail("isurub1992#gmail.com", "me", "Test", "This is a test message");
Email.sendMessage(service, "me", mimeMessage);
} catch (MessagingException ex) {
ex.printStackTrace();
}
P.S : I have added all the libraries and JavaEE API Library in NetBeasns
ClassNotFoundException is definite: the class is not found in classpath.
Short search reveals that the missing class com.sun.mail.util.MailLogger is found in com.sun.mail_1.4.2.jar; so have a look, I would place a bet that this would solve your problem.
Not the same problem, but it could be a nice information for you, too:
java.lang.NoClassDefFoundError: javax/mail/Authenticator, whats wrong?