First execution of Basic sample: Connecting error

Dear Gents,

It might be a very simple issue, I just runned the code of the Basic example and getting the error in the following line:

General client = new General(new JerseyClientImpl("Your API Key"));

This is the trace I get in the Console:

"C:\Program Files\Java\jdk1.6.0_38\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50023,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.6.0_38\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\resources.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\ext\sunmscapi.jar;C:\Users\acasanovas\Desktop\campaignmonitor-createsend\campaignmonitor-createsend-java-33c8865\build\libs\campaignmonitor-createsend-java-33c8865-2.6.0.jar;C:\DATA\Development\Campaign Monitor\TestSubscriptionCampaignMonitor\out\production\TestSubscriptionCampaignMonitor;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.0.2\lib\idea_rt.jar" TestSubscriptionCampaignMonitor
Connected to the target VM, address: '127.0.0.1:50023', transport: 'socket'
Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/core/MultivaluedMap
    at TestSubscriptionCampaignMonitor.runGeneralMethods(TestSubscriptionCampaignMonitor.java:94)
    at TestSubscriptionCampaignMonitor.main(TestSubscriptionCampaignMonitor.java:42)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.MultivaluedMap
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 2 more
Disconnected from the target VM, address: '127.0.0.1:50023', transport: 'socket'

Will appreciate your help.

Thank you,
Albert

jamesd jamesd, 1 year ago

Hey Albert,

If you're using IDEA (which it appears you are), did you use Gradle to create the project and module files?

gradle idea

Also, are you able to get a "BUILD SUCCESSFUL" result when you run the following?

gradle -i

javax.ws.rs.core.MultivaluedMap should definitely be found in the jersey-core jar file.

acasanovas, 1 year ago

Thank you James, I solved it by adding some jar files... Now I have the following issue:

"C:\Program Files\Java\jdk1.6.0_38\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:54643,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.6.0_38\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\resources.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.6.0_38\jre\lib\ext\sunmscapi.jar;C:\DATA\Development\Campaign Monitor\TestSubscriptionCampaignMonitor\out\production\TestSubscriptionCampaignMonitor;C:\DATA\Development\Campaign Monitor\jsr311-api-0.11.jar;C:\DATA\Development\Campaign Monitor\jersey-client-1.9.jar;C:\DATA\Development\Campaign Monitor\com.sun.jersey.jersey-core-1.4.0.jar;C:\DATA\Development\Campaign Monitor\jackson-jaxrs-1.0.1.jar;C:\DATA\Development\Campaign Monitor\campaignmonitor-createsend-java-33c8865-2.6.0.jar;C:\DATA\Development\Campaign Monitor\jersey-json-1.17.jar;C:\DATA\Development\Campaign Monitor\jettison-1.1.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.0.2\lib\idea_rt.jar" Tester
Connected to the target VM, address: '127.0.0.1:54643', transport: 'socket'
30-ene-2013 17:36:00 com.sun.jersey.api.client.ClientResponse getEntity
GRAVE: A message body reader for Java class [Lcom.createsend.models.clients.ClientBasics;, and Java type class [Lcom.createsend.models.clients.ClientBasics;, and MIME media type application/json;charset=utf-8 was not found
Disconnected from the target VM, address: '127.0.0.1:54643', transport: 'socket'
30-ene-2013 17:36:00 com.sun.jersey.api.client.ClientResponse getEntity
GRAVE: The registered message body readers compatible with the MIME media type are:
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
  com.sun.jersey.core.impl.provider.entity.ReaderProvider
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
  com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
  com.sun.jersey.core.impl.provider.entity.EntityHolderReader

Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class [Lcom.createsend.models.clients.ClientBasics;, and Java type class [Lcom.createsend.models.clients.ClientBasics;, and MIME media type application/json;charset=utf-8 was not found
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:549)
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:506)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:674)
    at com.sun.jersey.api.client.WebResource.get(WebResource.java:191)
    at com.createsend.util.JerseyClientImpl.get(JerseyClientImpl.java:146)
    at com.createsend.util.JerseyClientImpl.get(JerseyClientImpl.java:133)
    at com.createsend.util.JerseyClientImpl.get(JerseyClientImpl.java:107)
    at com.createsend.General.getClients(General.java:88)
    at Tester.main(Tester.java:9)


This is my code, where my APIKey is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxc0ed4

import com.createsend.General;
import com.createsend.models.clients.ClientBasics;
import com.createsend.util.JerseyClientImpl;
import com.createsend.util.exceptions.CreateSendException;

public class Tester {
    public static void main(String[] args) throws CreateSendException {
        General client = new General(new JerseyClientImpl("[client ID here]"));
        ClientBasics[] clients = client.getClients();
        for (ClientBasics c : clients) {
            System.out.printf("%s (ID: %s)\n", c.Name, c.ClientID);
        }
    }
}

The error is happing when executing this line:

ClientBasics[] clients = client.getClients();

I added jersey-json-1.17.jar in the classpath but still same issue.


Thank you,
Albert

acasanovas, 1 year ago

Hi, I executed gradle idea and now everything smooth. Thanks

Sign up for free.
Then send campaigns for as little as $9p/m

Create an account