Search code examples
androidsdkaws-sdkgatewayaws-api-gateway

Force close when try to Invoke method


I have a problem when I try to set up the client, I got the message: toString() failure in the factory.build. Method threw 'java.lang.IllegalArgumentException' exception. Cannot evaluate $Proxy1.toString() then when i call

ApiClientFactory factory = new ApiClientFactory();
factory.apiKey("xXxxXXXxxXXXXXXxxxxX");
final APIGatewayPediuClient client = factory.build(APIGatewayPediuClient.class); // exception happened in this line, proxy throw exepction

and when i try invoke the method

Places place = client.placesGet();

force close happens

com.amazonaws.http.UrlHttpClient.createHttpResponse(UrlHttpClient.java:72)
at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:66)
at com.amazonaws.mobileconnectors.apigateway.ApiClientHandler.invoke(ApiClientHandler.java:91)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy1.placesGet(Unknown Source)
at net.devsoft.pediu.activity.HomeActivity$override.onCreate(HomeActivity.java:195)
at net.devsoft.pediu.activity.HomeActivity$override.access$dispatch(HomeActivity.java)`

SDK version:

compile com.amazonaws:aws-android-sdk-core:2.2.6'
compile 'com.amazonaws:aws-android-sdk-cognito:2.2.6'
compile 'com.amazonaws:aws-android-sdk-apigateway-core:2.2.6'
compile 'com.google.code.gson:son:1.7.2

but already tried with aws version 2.2.15 and still doesnt work, the SDK generate to Obj-C its working perfectly


Solution

  • The solution is put this code inside a AsyncTask.

     new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
    
                 ApiClientFactory factory = new ApiClientFactory();
                 factory.apiKey("xXXxXXXXXXXxxxxXXxxXXXXxxx");
                 final APIGatewayPediuClient client = factory.build(APIGatewayPediuClient.class); 
                 Places place = client.placesGet();
                return null;
            }
        }.execute();