jimmoores / quandl4j

Java wrapper for Quandl REST API
quandl4j.org
Apache License 2.0
78 stars 22 forks source link

NoClassDefFoundError: QuandlSession or NoClassDefFoundError: ClassicQuandlSession #43

Closed stefanionescu closed 6 years ago

stefanionescu commented 6 years ago

Hi,

I'm trying to use your lib in Android Studio in a Java module that I made. I use gradle to get your code and then when I try to run either Example1 or Example2 I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/jimmoores/quandl/QuandlSession at com.demo.constant.volatilecommodities.Volatile.main(Volatile.java:14) Caused by: java.lang.ClassNotFoundException: com.jimmoores.quandl.QuandlSession 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) ... 1 more

With either QuandlSession or ClassicQuandlSession.

What do I do wrong?

jimmoores commented 6 years ago

What does your pom/gradle file look like? Have you included the core module?

On 8 Mar 2018 16:37, "Stefan Ionescu" notifications@github.com wrote:

Hi,

I'm trying to use your lib in Android Studio in a Java module that I made. I use gradle to get your code and then when I try to run either Example1 or Example2 I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/jimmoores/quandl/QuandlSession at com.demo.constant.volatilecommodities.Volatile.main(Volatile.java:14) Caused by: java.lang.ClassNotFoundException: com.jimmoores.quandl. QuandlSession 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) ... 1 more

With either QuandlSession or ClassicQuandlSession.

What do I do wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jimmoores/quandl4j/issues/43, or mute the thread https://github.com/notifications/unsubscribe-auth/AADG-1jmWPjhsohAgjyczlinj4CSe3Opks5tcV5FgaJpZM4Si-Ot .

stefanionescu commented 6 years ago

Gradle:


    apply plugin: 'java-library'

    dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])

      compile 'com.jimmoores:quandl-core:2.0.0'
    }

    sourceCompatibility = "1.7"
    targetCompatibility = "1.7" 

Actual code:

      public class myClass {

       public static void main(String[] args) {

        ClassicQuandlSession session = ClassicQuandlSession.create();
        TabularResult tabularResult = session.getDataSet(
                DataSetRequest.Builder.of("WIKI/AAPL").build());
        System.out.println(tabularResult.toPrettyPrintedString());
        }
    }  
jimmoores commented 6 years ago

Try changing 'compile' in the dependencies section to 'runtime'. I'm not really familiar with gradle but that looks wrong to me (my gradle instructions were provided by a contributor so I've never tested them).

On Fri, 9 Mar 2018, 18:58 Stefan Ionescu, notifications@github.com wrote:

Gradle:

`apply plugin: 'java-library'

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.jimmoores:quandl-core:2.0.0'

}

sourceCompatibility = "1.7" targetCompatibility = "1.7"`

Actual code:

`public class myClass {

public static void main(String[] args) {

ClassicQuandlSession session = ClassicQuandlSession.create();
TabularResult tabularResult = session.getDataSet(
        DataSetRequest.Builder.of("WIKI/AAPL").build());
System.out.println(tabularResult.toPrettyPrintedString());

}

}`

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jimmoores/quandl4j/issues/43#issuecomment-371912480, or mute the thread https://github.com/notifications/unsubscribe-auth/AADG-1KnKG19rFfgHYanjpZ8-5b-rryGks5tctDWgaJpZM4Si-Ot .

stefanionescu commented 6 years ago

Tried with runtime but it doesn't do the trick

jimmoores commented 6 years ago

It looks to me like your Gradle set-up isn't working. I'm not familiar with Gradle really but have you checked the libs directory to see if Gradle is actually pulling the library from maven central?

I see you're using the java-library plug-in. You might try the straight-up 'java' plug-in which doesn't require api and implementation separation (docs say that compile is supported but shouldn't be used).

As for what the part saying:

implementation fileTree(dir: 'libs', include: ['*.jar'])

do you know what that's doing?

stefanionescu commented 6 years ago

I can try with simple "java". The implementation part compiles jars which are in the libs folder.

In the worst case, I'll make a separate lib that works in Android Studio

benmccann commented 6 years ago

According to the Gradle docs for java-library you should have implementation 'com.jimmoores:quandl-core:2.0.0' instead of compile 'com.jimmoores:quandl-core:2.0.0'

runtime definitely won't work

Ultimately though this is a Gradle question and not a quandl4j question, so I'm going to close this issue