strongloop-community / loopback-sdk-android

Android Client SDK for the LoopBack framework.
Other
67 stars 41 forks source link

loginUser problem java.lang.NoSuchMethodError: No virtual method post #110

Closed paranoiasystem closed 6 years ago

paranoiasystem commented 8 years ago

I have created a model based on User. In my java code I have created these classes: Utenti.java

package com.marcoferraioli.gate42.passmuesum.loopback;

public class Utenti extends com.strongloop.android.loopback.User {
}

UtentiRepository.java

package com.marcoferraioli.gate42.passmuesum.loopback;

public class UtentiRepository extends com.strongloop.android.loopback.UserRepository<Utenti> {

    public interface LoginCallback extends com.strongloop.android.loopback.UserRepository.LoginCallback<Utenti> {

    }

    public UtentiRepository() {
        super("utenti", null, Utenti.class);
    }
}

this is part of code of the activity where I make to login

......
......
final RestAdapter adapter = new RestAdapter(getApplicationContext(), "http://xxxxxx.marcoferraioli.com:3000/api");
final UtentiRepository utentiRepo = adapter.createRepository(UtentiRepository.class);
......
......
utentiRepo.loginUser(username, password, new UtentiRepository.LoginCallback() {
                        @Override
                        public void onSuccess(AccessToken token, Utenti currentUser) {
                            Log.d("Success", token.getUserId() + ":" + currentUser.getId());
                            Intent myIntent = new Intent(getApplicationContext(), NextActivity.class);
                            startActivity(myIntent);
                            finish();
                        }

                        @Override
                        public void onError(Throwable t) {
                            Log.e("Chatome", "Login E", t);
                        }
                    });
......
......

But where i try to login I receive this error:

09-15 17:18:48.316 13166-13166/com.marcoferraioli.gate42.passmuesum E/AndroidRuntime: FATAL EXCEPTION: main Process: com.marcoferraioli.gate42.passmuesum, PID: 13166 java.lang.NoSuchMethodError: No virtual method post(Landroid/content/Context;Ljava/lang/String;[Lorg/apache/http/Header;Lorg/apache/http/HttpEntity;Ljava/lang/String;Lcom/loopj/android/http/ResponseHandlerInterface;)Lcom/loopj/android/http/RequestHandle; in class Lcom/strongloop/android/remoting/adapters/RestAdapter$RestHttpClient; or its super classes (declaration of 'com.strongloop.android.remoting.adapters.RestAdapter$RestHttpClient' appears in /data/data/com.marcoferraioli.gate42.passmuesum/files/instant-run/dex/slice-loopback-sdk-android-1.5.2_37a7b873dd8c3edb1e8ff47bba0449144d758c3a-classes.dex) at com.strongloop.android.remoting.adapters.RestAdapter$RestHttpClient.request(RestAdapter.java:473) at com.strongloop.android.remoting.adapters.RestAdapter.request(RestAdapter.java:204) at com.strongloop.android.remoting.adapters.RestAdapter.invokeStaticMethod(RestAdapter.java:136) at com.strongloop.android.remoting.adapters.RestAdapter.invokeStaticMethod(RestAdapter.java:109) at com.strongloop.android.remoting.Repository.invokeStaticMethod(Repository.java:115) at com.strongloop.android.loopback.UserRepository.loginUser(UserRepository.java:231) at com.marcoferraioli.gate42.passmuesum.LoginActivity$2.onClick(LoginActivity.java:118) at android.view.View.performClick(View.java:4756) at android.view.View$PerformClick.run(View.java:19749) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5253) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Sorry for my bad English

karolisg commented 7 years ago

I had a similar issue. Can you show your dependencies list?

serjooo commented 7 years ago

Some of the issues I saw in your code: 1) First of all in the UtentiRepository constructor you don't need to pass null anymore. If you check the super class only accepts to parameters so you can do this instead:

super("utenti", Utenti.class);

also make sure that on your server backend you have named the user object utenti while creating it. Because when you do the login Java invokes the http://xxxxxx.marcoferraioli.com:3000/api/utenti/login and if its name is different than utenti it will not know what to actually do and most probably return the error you are receiving.

2) Second make that your User model implements all the getters and setters and additional fields with their according types other than the normal strongloop User

3) You don't really need to implement the LoginCallBack interface in your UserRepository just do this instead:

utentiRepo.loginUser(username , password , new com.strongloop.android.loopback.UserRepository.LoginCallback<Utenti>()

I hope my answer is helpful. Happy coding!

noman3qau commented 5 years ago

Need to add Kotlin proguard rules to solve this problem.