Advertisement
Guest User

Untitled

a guest
Apr 25th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. Error:
  2. java.lang.NullPointerException
  3. at com.example.vid_me_app.FeedFragment$2.onResponse(FeedFragment.java:56)
  4. at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
  5. at android.os.Handler.handleCallback(Handler.java:725)
  6. at android.os.Handler.dispatchMessage(Handler.java:92)
  7. at android.os.Looper.loop(Looper.java:158)
  8. at android.app.ActivityThread.main(ActivityThread.java:5751)
  9. at java.lang.reflect.Method.invokeNative(Native Method)
  10. at java.lang.reflect.Method.invoke(Method.java:511)
  11. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
  12. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
  13. at dalvik.system.NativeStart.main(Native Method)
  14.  
  15. public interface VideoApi {
  16.  
  17. @GET("/videos/featured")
  18. Call<Videos> getFeaturedVideo();
  19.  
  20. @GET("/videos/new")
  21. Call<Videos> getNewVideo();
  22.  
  23. @FormUrlEncoded
  24. @POST("/auth/create")
  25. Call<SignInResults>insertUser(@Field("username") String username,
  26. @Field("password") String password
  27. );
  28. }
  29.  
  30. public class FeedFragment extends Fragment {
  31. EditText username;
  32. EditText password;
  33. Button btnLogin;
  34. public List<SignInResult> signInResult;
  35. public static final String ROOT_URL = "https://api.vid.me/";
  36. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  37. Bundle savedInstanceState) {
  38. View rootView = inflater.inflate(R.layout.fragment_feed, container, false);
  39. username = (EditText) rootView.findViewById(R.id.user_name_field);
  40. password = (EditText) rootView.findViewById(R.id.password_field);
  41. btnLogin = (Button)rootView.findViewById(R.id.button_login);
  42. btnLogin.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View v) {
  45. Authorize();
  46. }
  47. });
  48. return rootView;
  49. }
  50. public void Authorize(){
  51. Retrofit retrofitAdapter = new Retrofit.Builder()
  52. .addConverterFactory(GsonConverterFactory.create())
  53. .baseUrl(ROOT_URL)
  54. .build();
  55. final VideoApi videoApi = retrofitAdapter.create(VideoApi.class);
  56. Call<SignInResults> call = videoApi.insertUser(username.getText().toString(),password.getText().toString());
  57. call.enqueue(new Callback<SignInResults>() {
  58. @Override
  59. public void onResponse(Call<SignInResults> call, Response<SignInResults> response) {
  60.  
  61. signInResult = response.body().signInResults;
  62. Log.d("FeedFragment", "Username = " + signInResult.get(0).getUsername());
  63. }
  64.  
  65. @Override
  66. public void onFailure(Call<SignInResults> call, Throwable t) {
  67.  
  68. }
  69. });
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement