@4Geka
PHP

Ошибка при старте приложения, в чем проблема?

Здравствуйте, делаю приложение для html парсинга странички, но при старте вылетает сообщение ошибки.

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


Файлы где выдает ошибку дебагер:
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();
  }
}


В чем проблема подскажите?
  • Вопрос задан
  • 1708 просмотров
Пригласить эксперта
Ответы на вопрос 1
@onepavel
Консультация и разработка мобильных приложений
Тебе сказали в чем проблема и показали где проблема
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)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы