title: Null pointer Exception in TextView using RecyclerView
body: <p>I have build a RecyclerView and for that I have a CardAdapter. Following is the file:</p>
  
  <pre><code>public class CardAdapter extends RecyclerView.Adapter&lt;CardAdapter.ViewHolder&gt; {
  
  private ImageLoader imageLoader;
  private Context context;
  
  //List of Workers
  List&lt;Worker&gt; workersList;
  
  public class ViewHolder extends RecyclerView.ViewHolder{
      //   public NetworkImageView imageView;
      public TextView textViewName=new TextView(context);
      public RatingBar ratingBar;
  
      public ViewHolder(View itemView) {
          super(itemView);
  itemView.findViewById(R.id.profile_image);
          textViewName = (TextView) itemView.findViewById(R.id.WorkerName);
          ratingBar = (RatingBar) itemView.findViewById(R.id.ratingBar);
          Log.d("Workername",ratingBar.toString());  //no NPE error
      }
  }
  
  public CardAdapter(List&lt;Worker&gt; workersList, Context context){
      super();
      //Getting all the workers
      this.workersList = workersList;
      this.context = context;
  }
  
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View v = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.workers_list_view, parent, false);
      Log.d("view",v.toString());
      ViewHolder viewHolder = new ViewHolder(v);
      Log.d("textView",viewHolder.textViewName.toString());  //NPEerror on textView
      return viewHolder;
  }
  
  @Override
  public void onBindViewHolder(ViewHolder holder, final int position) {
      Log.d("pos",""+position);
      Worker worker =  workersList.get(position);
      Log.d("worker",""+worker.getName());
      holder.textViewName.setText(worker.getName());
      holder.ratingBar.setNumStars(worker.getRating());
   }
  
  @Override
  public int getItemCount() {
      return workersList.size();
  }
  }
  </code></pre>
  
  <p>And following is the Layout file workers_list_view.xml:</p>
  
  <pre><code>    &lt;android.support.v7.widget.CardView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/cv"
      app:cardBackgroundColor="@color/colorPrimaryDark"
      android:elevation="5dp"
      card_view:cardCornerRadius="@dimen/card_album_radius"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:padding="6dp"
          &gt;
  
          &lt;LinearLayout
              android:id="@+id/thumbnail"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_marginRight="5dip"
              android:padding="3dip" &gt;
  
              &lt;ImageView
                  android:id="@+id/profile_image"
                  android:layout_width="96dp"
                  android:layout_height="96dp"
                  android:src="@drawable/cover"
                  /&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;TextView
              android:id="@+id/WorkerName"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:text="Name of worker"
              android:layout_alignTop="@+id/thumbnail"
              android:layout_toRightOf="@+id/button2"
              android:layout_toEndOf="@+id/button2" /&gt;
  
          &lt;RatingBar
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/ratingBar"
              android:layout_centerVertical="true"
              android:layout_alignParentRight="true"
              android:layout_alignParentEnd="true" /&gt;
  
      &lt;/RelativeLayout&gt;
  
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p><strong>And following is the stack trace of the error I am getting:</strong></p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.widget.TextView.toString()' on a null object reference
  at com.appshaala.vorkal.app.CardAdapter.onCreateViewHolder(CardAdapter.java:60)
  at com.appshaala.vorkal.app.CardAdapter.onCreateViewHolder(CardAdapter.java:25)
  at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
  at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
  at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
  at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
  at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
  at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
  at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2625)
  at android.view.View.measure(View.java:18809)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
  at android.view.View.measure(View.java:18809)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
  at android.view.View.measure(View.java:18809)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
  at android.view.View.measure(View.java:18809)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at android.view.View.measure(View.java:18809)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
  at android.view.View.measure(View.java:18809)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
  at android.view.View.measure(View.java:18809)
  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2112)
  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1228)
  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1464)
  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
  at android.view.Choreographer.doCallbacks(Choreographer.java:670)
  at android.view.Choreographer.doFrame(Choreographer.java:606)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
  at android.os.Handler.handleCallback(Handler.java:746)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5443)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  </code></pre>
  
  <p>I have debugged the code and found that the ViewHolder and ratingBar is not null. Its is just the textView with the id WorkerName which is holding null value. I am stuck on this error.</p>
  
  <p>I am adding the class where I am using this card adapter:</p>
  
  <pre><code> public class ViewWorkerList extends AppCompatActivity {
  
  //Creating a List of workers
  private List&lt;Worker&gt; listWorkers;
  
  //Creating Views
  private RecyclerView recyclerView;
  private RecyclerView.LayoutManager layoutManager;
  private CardAdapter adapter;
  
  String url = "http://vorkal.com/read_data.php";
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; Item_List;
  public static final String KEY_SERVICE = "service";
  
  private String service;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Toast.makeText(getApplicationContext(),"2nd page",Toast.LENGTH_LONG);
      Log.d("2pg","2page");
      Intent intent = getIntent();
      service = intent.getStringExtra("service"); //if it's a string you stored.
      setContentView(R.layout.worker_list_main);
  
      //Initializing our workers list
      listWorkers = new ArrayList&lt;&gt;();
      Worker worker=new Worker();
      worker.setImageUrl("http://vorkal.com/images/vorkal_cover.PNG");
      worker.setName("name");
      worker.setLocation("location");
      worker.setRating(5);
      worker.setId(1);
      worker.setPhone(784512369);
      worker.setOccupation("occupation");
      worker.setPrice(20);
      worker.setReview("Review");
      listWorkers.add(worker);
  
      /*
      getData();
      //Log.d("listWorkers",listWorkers.get(0).getName());
      //Initializing Views
      recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
  
      //recyclerView.setAdapter(new CardAdapter(listWorkers, this));
      recyclerView.setHasFixedSize(true);
      layoutManager = new LinearLayoutManager(this);
      recyclerView.setLayoutManager(layoutManager);
      //Finally initializing our adapter
      adapter = new CardAdapter(listWorkers, this);
  
      //Adding adapter to recyclerview
      recyclerView.setAdapter(adapter);*/
  
      StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
              new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      Log.d("2pg",response);
                      Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show();
                      recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
  
                      //recyclerView.setAdapter(new CardAdapter(listWorkers, this));
                      recyclerView.setHasFixedSize(true);
                      layoutManager = new LinearLayoutManager(getApplicationContext());
                      recyclerView.setLayoutManager(layoutManager);
                      //Finally initializing our adapter
                      adapter = new CardAdapter(listWorkers, getApplicationContext());
                      recyclerView.setAdapter(adapter);
                  }
              },
              new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
                      Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_LONG).show();
                  }
              }){
          @Override
          protected Map&lt;String,String&gt; getParams(){
              Map&lt;String,String&gt; params = new HashMap&lt;String, String&gt;();
              params.put("tag", "get_list");
              params.put("service", service);
              return params;
          }
  
      };
  
      RequestQueue requestQueue = Volley.newRequestQueue(this);
      requestQueue.add(stringRequest);
  }
  </code></pre>
  
  <p>}</p>