Hello, I am making an application for parsing the html page, but when I start, an error message crashes. How to fix?

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) 

MoviesAdapter.java

 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; } } } 

Closed due to the fact that the essence of the question is incomprehensible to the participants dirkgntly , D-side , cheops , user194374, aleksandr barakin Aug 5 '16 at 8:03 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Without the code, there is nothing to say, except your collection ( ArrayList ) causes a NullPointerException , whether you are doing toArray() somewhere, or addAll() . - Silento
  • Without a code, they will simply give you a link to how to treat NPE. Add the code and there is a chance that the good uncles of the aunt will find an error - iFr0z
  • items.addAll (movies); That is - DevMarv
  • Check out the loadData movies method is not null? - Werder

0