2016-08-03 26 views
0

Ich entwickle eine Anwendung, die das Android SDK von Loopback für REST-Anforderungen verwendet. Ich habe ein Problem, wenn ich versuche, einen Benutzer anzumelden, erhalte ich, dass FehlerLoopBack Android nicht anmeldenUser

08-03 10:44:21.149 12375-12375/com.marcoferraioli.loopback E/Chatome: Login E 
                     org.apache.http.client.HttpResponseException: Not Found 
                      at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:404) 
                      at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:161) 
                      at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:178) 
                      at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:109) 
                      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
                      at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                      at java.lang.Thread.run(Thread.java:818) 

Ich habe Benutzerklasse

package com.marcoferraioli.loopback; 

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

und UserRepository Klasse erstellen

package com.marcoferraioli.loopback; 

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

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

    public UserRepository() { 
     super("admin", null, User.class); 
    } 

} 

dies MainActivity

package com.marcoferraioli.loopback; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.TextView; 

import com.strongloop.android.loopback.AccessToken; 
import com.strongloop.android.loopback.RestAdapter; 
import com.strongloop.android.loopback.callbacks.ListCallback; 

import java.util.List; 

public class MainActivity extends AppCompatActivity { 

    private TextView textProva; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     textProva = (TextView) findViewById(R.id.prova); 

     RestAdapter adapter = new RestAdapter(getApplicationContext(), "http://********:3000/api"); 

     OperaRepository operaRepository = adapter.createRepository(OperaRepository.class); 

     operaRepository.findAll(new ListCallback<Opera>(){ //This work 
      @Override 
      public void onSuccess(List<Opera> objects) { 
       for (Opera opera : objects){ 
        textProva.append("\n" + opera.toString()); 
       } 
      } 

      @Override 
      public void onError(Throwable t) { 
       Log.e("Error", "findAll", t); 
      } 
     }); 

     UserRepository userRepo = adapter.createRepository(UserRepository.class); 

     userRepo.loginUser("[email protected]" , "superadmin" , new UserRepository.LoginCallback() { 
      @Override 
      public void onSuccess(AccessToken token, User currentUser) { 
       textProva.append("\n" + token.getUserId() + ":" + currentUser.getId()); 
      } 

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

    } 
} 

Wie behebe ich dieses Problem?

PS: Ich habe dieses

Antwort

0

https://docs.strongloop.com/display/public/LB/Android+SDK#AndroidSDK-Usersandauthentication folgen ich lösen dieses Problem haben, ich habe in der UserRepository Klasse falsch, dies ist der richtige Code ist:

package com.marcoferraioli.loopback; 

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

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

    public UserRepository() { 
     super("user", null, User.class); 
    } 

} 

Im Konstruktor der erste Parameter der ist Name des Modells.