title: Getting java.lang.NullPointerException: Attempt to read from null array
body: <p>I am trying to create a RecyclerView in a Fragment and getting the below exception.
  I have tried everything but not able to find out what i am missing
  Here is my code.</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                    Process: com.code2hack.truckcalculator, PID: 15257
                    java.lang.NullPointerException: Attempt to read from null array
                        at android.widget.TableRow.measureNullChild(TableRow.java:183)
                        at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1127)
                        at android.widget.TableRow.onMeasure(TableRow.java:113)
                        at android.view.View.measure(View.java:23169)
                        at android.widget.TableRow.getColumnsWidths(TableRow.java:313)
                        at android.widget.TableLayout.findLargestCells(TableLayout.java:506)
                        at android.widget.TableLayout.measureVertical(TableLayout.java:471)
                        at android.widget.TableLayout.onMeasure(TableLayout.java:437)
                        at android.view.View.measure(View.java:23169)
                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
                        at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
                        at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
                        at android.view.View.measure(View.java:23169)
                        at android.support.v7.widget.RecyclerView$LayoutManager.measureChildWithMargins(RecyclerView.java:8994)
                        at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1585)
                        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
                        at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
                        at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
                        at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3225)
                        at android.view.View.measure(View.java:23169)
                        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
                        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                        at android.view.View.measure(View.java:23169)
                        at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)
                        at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)
                        at android.view.View.measure(View.java:23169)
                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
                        at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:739)
                        at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
                        at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
                        at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:809)
                        at android.view.View.measure(View.java:23169)
                        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1059)
                        at android.view.View.measure(View.java:23169)
                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
                        at android.view.View.measure(View.java:23169)
                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
                        at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
                        at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
                        at android.view.View.measure(View.java:23169)
                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                        at android.view.View.measure(View.java:23169)
                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
                        at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
                        at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
                        at android.view.View.measure(View.java:23169)
                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
  E/AndroidRuntime:     at com.android.internal.policy.DecorView.onMeasure(DecorView.java:716)
                        at android.view.View.measure(View.java:23169)
                        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2719)
                        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1572)
                        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1856)
                        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
                        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7184)
                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
                        at android.view.Choreographer.doCallbacks(Choreographer.java:761)
                        at android.view.Choreographer.doFrame(Choreographer.java:696)
                        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
                        at android.os.Handler.handleCallback(Handler.java:873)
                        at android.os.Handler.dispatchMessage(Handler.java:99)
                        at android.os.Looper.loop(Looper.java:193)
                        at android.app.ActivityThread.main(ActivityThread.java:6669)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  </code></pre>
  
  <p>Here is my Fragment class </p>
  
  <pre><code>package com.code2hack.truckcalculator.fragments;
  
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v4.app.Fragment;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import com.code2hack.truckcalculator.R;
  import com.code2hack.truckcalculator.adapter.MonthlyListAdapter;
  import com.code2hack.truckcalculator.model.DayData;
  import com.code2hack.truckcalculator.model.Expense;
  
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.List;
  import java.util.Random;
  
  public class MonthlyRecordFragment  extends Fragment {
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.monthly_record,container,false);
          setRecyclerView(view);
          return view;
      }
  
      public void setRecyclerView(View view){
          RecyclerView recyclerView = view.findViewById(R.id.dailylist);
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          MonthlyListAdapter adapter = new MonthlyListAdapter(getActivity(),getList());
          recyclerView.setAdapter(adapter);
      }
      public List&lt;DayData&gt; getList(){
          List&lt;DayData&gt; dayData = new ArrayList&lt;&gt;();
          Calendar calendar = Calendar.getInstance();
  
          for(int i=0;i&lt;220;i++){
              DayData data = new DayData();
              data.setDate(calendar.getTime());
              calendar.add(Calendar.DATE,1);
              data.setFrom("kkkkkkkk");
              data.setTo("bbbbbbbb");
              List&lt;Expense&gt; expenses = new ArrayList&lt;&gt;();
              for(int j=0;j&lt;4;j++){
                  Expense expense = new Expense();
                  expense.setName("Name " + (j+1));
                  expense.setPrice(new Random().nextInt() * 2000);
                  expenses.add(expense);
              }
              data.setData(expenses);
              dayData.add(data);
          }
          return dayData;
      }
  }
  </code></pre>
  
  <p>And my Adapter class</p>
  
  <pre><code>package com.code2hack.truckcalculator.adapter;
  
  import android.content.Context;
  import android.support.annotation.NonNull;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TableLayout;
  import android.widget.TextView;
  
  import com.code2hack.truckcalculator.R;
  import com.code2hack.truckcalculator.model.DayData;
  import com.code2hack.truckcalculator.model.Expense;
  
  import java.text.SimpleDateFormat;
  import java.util.List;
  
  public class MonthlyListAdapter extends RecyclerView.Adapter&lt;MonthlyListAdapter.DailyViewHolder&gt; {
      private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
      private List&lt;DayData&gt; data;
      LayoutInflater inflater;
      Context context;
      public MonthlyListAdapter(Context context, List&lt;DayData&gt; data){
          this.context = context;
          this.data = data;
          this.inflater = LayoutInflater.from(context);
      }
  
      @NonNull
      @Override
      public DailyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View view = inflater.inflate(R.layout.daily_data_item,parent,false);
          DailyViewHolder viewHolder = new DailyViewHolder(view);
  
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(@NonNull DailyViewHolder holder, int position) {
          DayData record = data.get(position);
          holder.setData(record);
      }
  
      @Override
      public int getItemCount() {
          return data.size();
      }
  
      class DailyViewHolder extends RecyclerView.ViewHolder {
          private View view;
          public DailyViewHolder(View itemView) {
              super(itemView);
              this.view = itemView;
          }
          public void setData(DayData data){
              String date = dateFormat.format(data.getDate());
              String sourceDestination = data.getFrom() + " -&gt; " + data.getTo();
  
              TextView dateView = view.findViewById(R.id.record_date);
              dateView.setText(date);
  
              TextView destination = view.findViewById(R.id.destination);
              destination.setText(sourceDestination);
  
              TableLayout table = view.findViewById(R.id.datatable);
              table.removeAllViews();
  
              for(Expense expense :data.getData()) {
                  View row = inflater.inflate(R.layout.expence_display, table, false);
  
                  TextView textView = row.findViewById(R.id.key);
                  textView.setText(expense.getName());
  
                  TextView valueTag = row.findViewById(R.id.value);
                  valueTag.setText(String.valueOf(expense.getPrice()));
                  table.addView(row);
              }
  
          }
      }
  }
  </code></pre>
  
  <p>monthly_record.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/dailylist"&gt;
      &lt;/android.support.v7.widget.RecyclerView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I am not able to find out what i am missing.
  Any help will be appreciated.Anybody please help me.</p>