title: ListView in Fragment with adapter - can't add new objects - FATAL EXCEPTION
body: <p>I'm creating an app with a tab layout consisting of three fragments. In one of these 3 Fragments I would like to have a ListView. And I would like to add ToSave objects to the ListView. I tried to add objects to the ListView from another Fragment using interface and following lines:</p>
  
  <pre><code>ToSave toSave = new ToSave();
  HistoryFragment.adapter.add(toSave);
  HistoryFragment.adapter.notifyDataSetChanged();
  </code></pre>
  
  <p>but I am still getting <code>FATAL EXCEPTION: main</code> when swiping to this tab. Even if I put:</p>
  
  <pre><code>ToSave toSave = new ToSave();
  adapter.add(toSave);
  </code></pre>
  
  <p>inside <code>onCreateView</code> in <strong>HistoryFragment.java</strong> I'm getting the same error.</p>
  
  <p>My code is below. I've already implemented adapter (don't know if correctly):</p>
  
  <h3>HistoryFragment.java</h3>
  
  <pre><code>public class HistoryFragment extends Fragment {
      ListView listView;
      HistoryAdapter adapter;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View history = inflater.inflate(R.layout.fragment_history, container, false);
          ArrayList&lt;ToSave&gt; arrayOfData = new ArrayList&lt;ToSave&gt;();
          adapter = new HistoryAdapter(getActivity().getBaseContext(), arrayOfData);
          listView = (ListView) history.findViewById (R.id.listView1);
          listView.setAdapter(adapter);
          ToSave toSave = new ToSave();
          adapter.add(toSave);
          return history;
  
      }
  }
  </code></pre>
  
  <h3>ToSave.java</h3>
  
  <pre><code>public class ToSave {
  
      public int numberBooks;
      public int numberPages;
  
  
      public ToSave() {
  
          numberBooks = 500;
          numberPages = 10000;
      }
  }
  </code></pre>
  
  <h3>HistoryAdapter.java</h3>
  
  <pre><code>public class HistoryAdapter extends ArrayAdapter&lt;ToSave&gt;{
  
      public HistoryAdapter(Context context, ArrayList&lt;ToSave&gt; records) {
          super(context, R.layout.history_item, records);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ToSave record = getItem(position);
          if (convertView == null) {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.history_item, parent, false);
          }
          TextView tvBooks = (TextView) convertView.findViewById(R.id.textViewBooks);
          TextView tvPages = (TextView) convertView.findViewById(R.id.textViewPages);
          // Populate the data into the template view using the data object
          tvBooks.setText(record.numberBooks);
          tvPages.setText(record.numberPages);
          // Return the completed view to render on screen
          return convertView;
  
      }
  }
  </code></pre>
  
  <h3>fragment_history.xml</h3>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center"
      android:orientation="vertical" 
      android:background="#E3F6CE"&gt;
  
      &lt;ListView
          android:id="@+id/listView1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
      &lt;/ListView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <h3>history_item.xml</h3>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/textViewBooks"
          android:paddingLeft="2dp"
          android:textSize="20dp"
          android:textStyle="bold"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Date" /&gt;
  
      &lt;TextView
          android:id="@+id/textViewPages"
          android:paddingLeft="5dp"
          android:textSize="17dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Data" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I've tried to solve the problem by myself for many hours, but didn't find any solution.</p>
  
  <p>Many thanks for your help!!!</p>
  
  <h2>EDIT</h2>
  
  <h3>logcat:</h3>
  
  <pre><code>08-06 19:02:44.295: D/OpenGLRenderer(26412): Enabling debug mode 0
  08-06 19:02:44.355: I/ActivityManager(26412): Timeline: Activity_idle id: android.os.BinderProxy@44ff1e10 time:112732348
  08-06 19:02:45.445: W/ResourceType(26412): No package identifier when getting value for resource number 0x000001f4
  08-06 19:02:45.445: D/AndroidRuntime(26412): Shutting down VM
  08-06 19:02:45.445: W/dalvikvm(26412): threadid=1: thread exiting with uncaught exception (group=0x41e5cd88)
  08-06 19:02:45.455: E/AndroidRuntime(26412): FATAL EXCEPTION: main
  08-06 19:02:45.455: E/AndroidRuntime(26412): Process: com.example.booker, PID: 26412
  08-06 19:02:45.455: E/AndroidRuntime(26412): android.content.res.Resources$NotFoundException: String resource ID #0x1f4
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.content.res.Resources.getText(Resources.java:252)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.TextView.setText(TextView.java:3905)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at com.example.booker.HistoryAdapter.getView(HistoryAdapter.java:27)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.AbsListView.obtainView(AbsListView.java:2255)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.ListView.onMeasure(ListView.java:1175)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.View.measure(View.java:16628)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.View.measure(View.java:16628)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.View.measure(View.java:16628)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1456)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.View.measure(View.java:16628)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.View.measure(View.java:16628)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.View.measure(View.java:16628)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2298)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.View.measure(View.java:16628)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5622)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.Choreographer.doFrame(Choreographer.java:544)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.os.Handler.handleCallback(Handler.java:733)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.os.Handler.dispatchMessage(Handler.java:95)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.os.Looper.loop(Looper.java:212)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at android.app.ActivityThread.main(ActivityThread.java:5135)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at java.lang.reflect.Method.invokeNative(Native Method)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at java.lang.reflect.Method.invoke(Method.java:515)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
  08-06 19:02:45.455: E/AndroidRuntime(26412):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>