crazzyghost / alphavantage-java

Fluent Java wrapper for Alpha Vantage API
MIT License
80 stars 35 forks source link

A request #6

Closed MMMins closed 4 years ago

MMMins commented 4 years ago

Hello, i'm writing you so as to ask a little thing. I tryied to use your project so as to connect it to project i'm working on in java. Anyway it throws an exception everytime i try to start it. I'm probably missing something in the code so i'd like to ask you if you may let me know wheter there is or not an error in the code i'm sending you. Thanks anyway for your attention and your useful project.

Here's the code of the main i class i wrote just to understand the functioning. ///////////////////////////////////////////////////////////////////////////////////////

import com.crazzyghost.alphavantage.parameters.Interval; import com.crazzyghost.alphavantage.parameters.OutputSize; import com.crazzyghost.alphavantage.timeseries.response.TimeSeriesResponse;

public class Main {

public static void main(String[] args) 
{
     Main main = new Main();
     main.init();
}

public void init() {
    //initializer
    Config cfg = Config.builder()
            .key(//my key//)    //i'm just hiding my key there but it's explicited in the project
            .timeOut(100)
            .build();

    AlphaVantage.api().init(cfg);

    AlphaVantage.api()
    .timeSeries()
        .intraday()
    .forSymbol("AAPL")
    .interval(Interval.ONE_MIN)
    .outputSize(OutputSize.FULL)
    .dataType(DataType.JSON)
        .onSuccess(e->handleSuccess((TimeSeriesResponse) e))
         .onFailure(e->handleFailure((e)))
    .fetch();

}

public void handleSuccess(TimeSeriesResponse response) {
    System.out.println("Function");
    System.out.println(response.toString());
}

public void handleFailure(AlphaVantageException error) {

    System.out.println("Doesn't function");
   System.out.println(error.getMessage());
}   

}

///////////////////////////////////////////////////////////////////////

The error it gives me when i try to execute it is the following one:

/////////////////////////////////////////////////////////////////////

Exception in thread "OkHttp Dispatcher" java.lang.NoSuchMethodError: okio.BufferedSource.getBuffer()Lokio/Buffer; at com.squareup.moshi.JsonUtf8Reader.(JsonUtf8Reader.java:97) at com.squareup.moshi.JsonReader.of(JsonReader.java:196) at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:40) at com.crazzyghost.alphavantage.timeseries.TimeSeries$1.onResponse(TimeSeries.java:89) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:835)

///////////////////////////////////////////////////////////////////////////////////

Thank another time for your attention and help.

crazzyghost commented 4 years ago

@MMMins, I ran your code and its working fine when building with gradle (android/java).With maven I'm able to reproduce your case. It seems to be an issue with the okhttp dependency. I will look further into this

MMMins commented 4 years ago

Ok thanks, i'll try to build it with gradle.

crazzyghost commented 4 years ago

@MMMins you can now build with maven using the latest version (v1.3.2). It was an issue with the previous gradle configuration which prevented the download of external libraries.