M
M
Makfroy2016-08-02 16:50:06
Computer networks
Makfroy, 2016-08-02 16:50:06

Error when starting the application, what's the problem?

Hello, I'm making an application for html parsing a page, but an error message pops up at startup.

08-02 14:22:32.604 2776-2776/com.ekchang.jsouper.sample W/System: ClassLoader referenced unknown path: /data/app/com.ekchang.jsouper.sample-1/lib/x86
08-02 14:22:48.317 2776-2776/com.ekchang.jsouper.sample W/System: ClassLoader referenced unknown path: /data/app/com.ekchang.jsouper.sample-1/lib/x86
08-02 14:22:49.158 2776-2786/com.ekchang.jsouper.sample W/art: Suspending all threads took: 16.367ms
08-02 14:22:49.655 2776-2782/com.ekchang.jsouper.sample W/art: Suspending all threads took: 12.761ms
08-02 14:22:49.790 2776-2776/com.ekchang.jsouper.sample W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-02 14:22:50.162 2776-2782/com.ekchang.jsouper.sample W/art: Suspending all threads took: 17.582ms
08-02 14:22:50.329 2776-3124/com.ekchang.jsouper.sample D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
08-02 14:22:50.402 2776-3124/com.ekchang.jsouper.sample I/OpenGLRenderer: Initialized EGL, version 1.4
08-02 14:22:50.460 2776-3124/com.ekchang.jsouper.sample W/EGL_emulation: eglSurfaceAttrib not implemented
08-02 14:22:50.460 2776-3124/com.ekchang.jsouper.sample W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa17bfc0, error=EGL_SUCCESS
08-02 14:22:51.037 2776-2776/com.ekchang.jsouper.sample D/AndroidRuntime: Shutting down VM
                                                                          
                                                                          
                                                                          --------- beginning of crash
08-02 14:22:51.038 2776-2776/com.ekchang.jsouper.sample E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: com.ekchang.jsouper.sample, PID: 2776
                                                                          java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference
                                                                              at java.util.ArrayList.addAll(ArrayList.java:188)
                                                                              at com.ekchang.jsouper.sample.MoviesAdapter.loadData(MoviesAdapter.java:47)
                                                                              at com.ekchang.jsouper.sample.PlayStoreActivity$1.onResponse(PlayStoreActivity.java:53)
                                                                              at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
                                                                              at android.os.Handler.handleCallback(Handler.java:739)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:148)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-02 14:26:35.047 2776-2782/com.ekchang.jsouper.sample W/art: Suspending all threads took: 7.464ms
08-02 14:27:51.158 2776-2776/com.ekchang.jsouper.sample I/Process: Sending signal. PID: 2776 SIG: 9

Files where the debugger gives an error:
MoviesAdapter.java:47
public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.ViewHolder> {
  private List<Movie> items = new ArrayList<>();

  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    return new ViewHolder(
        (ItemMoviesBinding) DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
            viewType, parent, false));
  }

  @Override
  public void onBindViewHolder(ViewHolder holder, int position) {
    Movie movie = items.get(position);
    Picasso.with(holder.binding.getRoot().getContext())
        .load(movie.cover.imageUrl)
        .into(holder.binding.cover);

    holder.binding.title.setText(movie.detail.title);
    holder.binding.price.setText(movie.rating.price);
  }

  @Override
  public int getItemViewType(int position) {
    return R.layout.item_movies;
  }

  @Override
  public int getItemCount() {
    return items.size();
  }

  public void loadData(List<Movie> movies) {
    items.clear();
    items.addAll(movies);
    notifyItemRangeInserted(0, movies.size());
  }

  static class ViewHolder extends RecyclerView.ViewHolder {
    public final ItemMoviesBinding binding;

    public ViewHolder(ItemMoviesBinding binding) {
      super(binding.getRoot());
      this.binding = binding;
    }
  }
}

PlayStoreActivity.java:53
public class PlayStoreActivity extends AppCompatActivity {

  private ActivityMainBinding binding;
  private MoviesAdapter adapter;
  private PlayStoreApi playStoreApi;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_main);

    setSupportActionBar(binding.toolbar);

    adapter = new MoviesAdapter();
    binding.listMovies.setLayoutManager(new GridLayoutManager(this, 2));
    binding.listMovies.addItemDecoration(new GridSpacingDecoration(
        getResources().getDimensionPixelSize(R.dimen.movie_card_spacing)));
    binding.listMovies.setAdapter(adapter);
    binding.listMovies.setItemAnimator(new GridItemAnimator());

    Retrofit retrofit = new Retrofit.Builder().baseUrl(PlayStoreApi.BASE_URL)
        .addConverterFactory(JsoupConverterFactory.create())
        .build();

    playStoreApi = retrofit.create(PlayStoreApi.class);
    loadMovies();
  }

  public void loadMovies() {
    showLoading();
    playStoreApi.getMovies().enqueue(new Callback<List<Movie>>() {
      @Override
      public void onResponse(Call<List<Movie>> call, Response<List<Movie>> response) {
        hideLoading();
        adapter.loadData(response.body());
      }

      @Override
      public void onFailure(Call<List<Movie>> call, Throwable t) {
        hideLoading();
        Toast.makeText(PlayStoreActivity.this, "Error loading movies from Play Store",
            Toast.LENGTH_SHORT).show();
      }
    });
  }

  public void showLoading() {
    binding.loading.show();
  }

  public void hideLoading() {
    binding.loading.hide();
  }
}

What is the problem please?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2016-08-02
@onepavel

You were told what the problem was and showed where the problem
was java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object [] java.util.Collection.toArray ()' on a null object reference
at java.util.ArrayList. addAll (ArrayList.java:188)
at com.ekchang.jsouper.sample.MoviesAdapter.loadData (MoviesAdapter.java:47)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question