title: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference in recyclerview
body: <p>Hello everyone I'm working with an app and I'm consuming rest api using retrofit2. I have a list of companies that I need to show using recyclerview. I have followed a lot of resources and tutorials but none helped me. In the logcat session I have an error:  java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference in my adapter....</p>
  
  <p>in this line :</p>
  
  <pre><code>@Override
  public int getItemCount() {
      return companies.size();
  }
  </code></pre>
  
  <p>Here is my code: 
  my adapter</p>
  
  <pre><code>private List&lt;Company&gt; companies;
  private Context context;
  
  public CompanyAdapter(List&lt;Company&gt; companies, Context context) {
      this.companies = companies;
      this.context = context;
  }
  
  @NonNull
  @Override
  public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
      View view = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.row_companies, parent, false);
      return new ViewHolder(view);
  }
  
  @Override
  public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
      Company comp = companies.get(position);
  
      viewHolder.compName.setText(comp.getName());
      viewHolder.compDesc.setText(comp.getDescription());
      viewHolder.compNipt.setText(comp.getNipt());
  }
  
  @Override
  public int getItemCount() {
      return companies.size();
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder {
  
      public TextView compName, compDesc, compNipt;
  
      public ViewHolder(@NonNull View itemView) {
          super(itemView);
  
          compName = (TextView) itemView.findViewById(R.id.tvCompanyName);
          compDesc = (TextView) itemView.findViewById(R.id.tvCompanyDescription);
          compNipt = (TextView) itemView.findViewById(R.id.tvCompanyNipt);
      }
  }
  </code></pre>
  
  <p>and my activity</p>
  
  <pre><code>private RecyclerView recyclerView;
  private RecyclerView.Adapter adapter;
  private List&lt;Company&gt; companies;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_companies_list);
  
      RecyclerView recyclerView = (RecyclerView) findViewById(R.id.companies_list);
      recyclerView.setHasFixedSize(true);
      recyclerView.setLayoutManager(new LinearLayoutManager(this));
  
      adapter = new CompanyAdapter(companies, this);
      recyclerView.setAdapter(adapter);
  }
  </code></pre>
  
  <p>What I'm doing wrong...
  Any help is appreciated!</p>