Force close when try to Invoke method
Asked Answered
R

2

6

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

Ramos answered 24/4, 2016 at 17:0 Comment(0)
A
1

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();
Athamas answered 24/4, 2016 at 19:9 Comment(1)
Tried this inside of an AsyncTask. Still yeilds the same exact messageNervy
S
2

1 - Make sure to add Internet permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />

Note: uses-permission goes before application tag. i.e:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.awsapigatwway">
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

2 - Make sure to execute your API Gateway call within an ASyncTask

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ApiClientFactory factory = new ApiClientFactory();

            final PetStoreClient client = factory.build(PetStoreClient.class);

            Pet pet = client.petsPetIdGet("1");

            Log.d(pet.getType(), String.valueOf(pet.getPrice()));

            return null;
        }
    }.execute();
}

In this case, response should be seen on Logcat Debug.

Swee answered 8/12, 2018 at 10:1 Comment(0)
A
1

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();
Athamas answered 24/4, 2016 at 19:9 Comment(1)
Tried this inside of an AsyncTask. Still yeilds the same exact messageNervy

© 2022 - 2024 — McMap. All rights reserved.