I was trying to run the sample code from the sdk but I got the java.lang.NoClassDefFoundError, at the line:
sinchClient = Sinch.getSinchClientBuilder()
.context(this)
.userId("a")
.applicationKey("key")
.applicationSecret("secret")
.environmentHost("sandbox.sinch.com")
.build();
NoClassDefFoundError means it can't find the class. This is most likely because the Sinch RTC SDK is not properly included in your APK. Make sure that the .jar file is under your libs/ folder (or, if you are using a custom setup, make sure it's being compiled in to the final package).
Related
I have a java web application secured with OKTA. I have the below code which throws the below exception,
Client client = Clients.builder()
.setOrgUrl((String)SessionUtils.getSession().getAttribute("serverUrl"))
.setClientCredentials(new TokenClientCredentials((String)SessionUtils.getSession().getAttribute("apiKey")))
.build();
When I run it, I get the below error. I have tried adding the jar by going to the buildPath of eclipse project. I am using the below dependencies in my POM and this used to work before when my project had an ANT build. But I started getting this error when I moved to Maven.
java.lang.IllegalStateException: Unable to find a
'com.okta.sdk.impl.http.RequestExecutorFactory' implementation on the
classpath. Please ensure you have added the okta-sdk-httpclient.jar
file to your runtime classpath. at
com.okta.commons.lang.Classes.lambda$loadFromService$0(Classes.java:205)
at java.util.Optional.orElseThrow(Optional.java:290) at
com.okta.commons.lang.Classes.loadFromService(Classes.java:205) at
com.okta.sdk.impl.client.BaseClient.createRequestExecutor(BaseClient.java:103)
at com.okta.sdk.impl.client.BaseClient.(BaseClient.java:72) at
com.okta.sdk.impl.client.AbstractClient.(AbstractClient.java:60)
at
com.okta.sdk.impl.client.DefaultClient.(DefaultClient.java:117)
at
com.okta.sdk.impl.client.DefaultClientBuilder.build(DefaultClientBuilder.java:322)
I could resolve this by using the okta-sdk-httpclient :v1.5.2 to match some of the other OKTA dependencies that I had in my project.
Below are the dependencies that I had in my project prior to the fix.
-okta-authn-sdk-api :v1.0.0
-okta-authn-sdk-impl :v1.0.0
-okta-http-api :v1.2.8
-okta-commons-lang :v1.2.8
-okta-config-check :v1.2.8
-okta-http-okhttp :v1.2.8
-okta-jwt-verifier :v0.5.1
-okta-jwt-verifier-impl:v0.4.0
-okta-sdk :v0.0.4
-okta-sdk-api :v1.5.2
-okta-sdk-httpclient :v6.0.0
-okta-sdk-impl :v1.5.2
I have a .aar file that contains a SDK, it needs the gson library to work, so i added the gson.jar file into the project as a ReferenceJar, but it cannot find the reference.
I've already tried to extract the jar from the aar, and use one as InputJar and the gson jar as ReferenceJar, it did not work.
In this case the java code spits this error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/Gson;
I've tried to create a separate project that contains only the gson file as a InputJar and use it as a dependency on the other project.
In this case the gson project does not compile, VS spits errors like
CS0534 "CollectionTypeAdapterFactory.Adapter" does not implement inherited abstract member "TypeAdapter.Read(JsonReader)"
I've also tried to add the gson.jar file into the libs folder inside the .aar file, but gave me the same compiling errors as described above
So, what should I do next?
I figured out.
I had to extract the jar from the .aar and set it as an EmbeddedJar and the gson library as EmbeddedReferenceJar. Somehow it worked. If someone could explain me why, it would be nice.
I have the following task in my Android build.gradle file which copies my built APK file for me:
/**
* Copies the final release APK into the project root folder.
*/
task copyRelease(type: Copy) {
// define output files exactly to work around a file locking issue
outputs.files.setFrom(file("../app-release.apk"))
from "build/outputs/apk/app-release.apk"
into ".."
}
This has been working for a long time and broke today when doing Android Studio's suggested update:
Android Gradle plugin v2.3.0 (from v2.2.3)
Gradle v3.3 (from v2.14.1)
Running the Grade build now gives the following error on the line outputs.files.setfrom(...):
No signature of method: org.gradle.api.internal.tasks.DefaultTaskOutputs$TaskOutputUnionFileCollection.setFrom() is applicable for argument types: (java.io.File) values: [..\app-release.apk]
Possible solutions: sort()
To summarise, it seems like TaskOutputUnionFileCollection.setFrom() no longer takes File parameters.
But I do not know how to migrate this code to the new version and a look through the source class has not helped me.
I have looked at the Android Gradle plugin Known Issues page as well as the Gradle 3.3. Release Notes, and found no direct reference to this.
I could not find a direct & exact translation of the above code without implementing a workaround. The problem lies in using the root folder of the project for the destination of the copy command.
The workaround was to create a separate folder ..\release and then the following code works fine:
/**
* Copies the final release APK into the project root folder.
*/
task copyRelease(type: Copy) {
from "build/outputs/apk"
into "../release"
include "app-release.apk"
}
In my Android Studio project, I added the following build type to the build.gradle file:
jnidebug.initWith(buildTypes.debug)
jnidebug {
packageNameSuffix ".jnidebug"
jniDebuggable true
}
The documentation at:
http://tools.android.com/tech-docs/new-build-system/user-guide
says:
For each Build Type, a new matching sourceSet is created, with a
default location of src/<buildtypename>/
But when I resync gradle, the source code folder src/jnidebug never gets created. What am I doing wrong?
The documentation says that for each build type, a source set (which is a logical concept/domain object) is created and configured with a default location. It doesn't say that a source directory is created. You'll probably have to create the directory yourself. (Android Studio could certainly help with that, so perhaps file a feature request.)
I'm trying a project for school using JMS and ActiveMQ.
I copied the block of code from O'Reilly's books "Java Message Service 2nd Edition Jun 2009". It uses the publish and subscribe method and is in fact a small chat where everyone connected to the topic can send messages to everyone and everyone can see everyone else's messages. I compile the program and everything is ok, i try to run it and it gives me the following exception:
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.activemq.jndi.ActiveMQInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.activemq.jndi.ActiveMQInitialContextFactory]
I found that this problem might be because of 2 reasons:
activemq-all-5.2.0.jar is not added to classpath.
BUT added it the classpath (EnvironmentVariables->select ClassPath->Edit and add the following: "D:\Programming\JMS\ActiveMQ\apache-activemq-5.2.0" (THIS IS HOW YOU ADD IT NO?!?!)
jndi.properties file is not defined properly or has not been added to the classpath.
BUT i CREATED IT and added it's folder to the classpath. Here is what it contains:
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://localhost:61616
java.naming.security.principal=system
java.naming.security.credentials=manager
connectionFactoryNames = TopicCF
topic.topic1 = jms.topic1
What is the problem? I have tried for ages to make it work. Am i doing something wrong? :(
Does the jndi.properties file path matter? or it only has to be placed in classpath and from here it can be found?
I also ran the activemq.bat from the bin folder D:\Programming\JMS\ActiveMQ\apache-activemq-5.2.0\bin\
[Edit]---------------------
So it works in Eclipse, BUT
Now i've properly added the .jar file in environment variables and i've run the client from windows's cmd. It doesn't give any errors, when i write in Eclipse's console, it appears in cmd console, everything ok, but when i try to write in cmd it gives an error at this line:
publisher.publish(message);
and it says
java.lang.NoSuchMethodError: org.apache.activemq.ActiveMQMessageProducerSupport.getDestination()Ljavax/jms/Destination;
Any ideas? I'd really like to be able to run it in CMD. :(
---------------------[/Edit]
Well I'm on Linux right now, but I bet it has to be:
D:\Programming\JMS\ActiveMQ\apache-activemq-5.2.0.jar
Also, if you run it with Eclipse and go to Project -> Build Path and this jar then there shouldn't be any problems. Anyhow can you post the CLASSPATH variable?
EDIT
I can't help you if you can't help me. This is related to any other future questions or work in general, provide details - it is always helpful. Will be much helpful if you would provide the EXACT command that you are running in CMD and the code of the class where this happens.
java.lang.NoSuchMethodError
generally it means that the jar is in place, class also, BUT the method is not. It happens when you compile with one version of the jar and at runtime provide a jar where this method was removed, thus the JRE can't find it throwing the error.
I just tested on my computer
I do not understand why it does not work for you, but it does for me. Here is my class:
package com.test;
public class Publisher {
public static void main(String[] args) {
try{
ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = factory.createConnection();
ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic destination = session.createTopic("FOO.TEST");
TextMessage textMessage = session.createTextMessage("Sample Payload");
TopicPublisher publisher = session.createPublisher(destination);
publisher.publish(textMessage);
session.close();
connection.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
Everything is fine if I run it from eclipse with one single dependency in Maven:
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.2.0</version>
Then I do it with java and javac
javac -classpath /home/eugen/.m2/repository/org/apache/activemq/activemq-core/5.2.0/activemq-core-5.2.0.jar:/home/eugen/.m2/repository/javax/jms/jms/1.1/jms-1.1.jar Publisher.java
Notice that the only thing I added is the two jars.
Then java:
java -classpath /home/eugen/.m2/repository/org/apache/activemq/activemq-core/5.2.0/activemq-core-5.2.0.jar:/home/eugen/.m2/repository/commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.jar:/home/eugen/.m2/repository/org/apache/camel/camel-core/1.5.0/camel-core-1.5.0.jar:/home/eugen/workspace/t/src/main/java/:/home/eugen/.m2/repository/javax/jms/jms/1.1/jms-1.1.jar:/home/eugen/.m2/repository/org/apache/geronimo/specs/geronimo-j2ee-management_1.0_spec/1.0/geronimo-j2ee-management_1.0_spec-1.0.jar com.test.Publisher
I added a few needed jars to the classpath and run it - it works perfectly.
Cheers, Eugene.
I ran into the same issue and it was a space (or what appeared to be a space) at the end of my property config.
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
Also note that you don't necessarily have to embed the jar file into your client code. Simply including the activemq-all as a maven dependency will work as well.