title: How to set the ArrayList<custom> data in to the ListView in another fragment which extends listView?
body: <p>How to set the ArrayList data in to the ListView in another fragment which extends listView?</p>
  
  <p><strong>Help will be much appreciated from you experts out there.</strong></p>
  
  <p>Custom ArrayList takes int, string, string.
  I get the user input from two EditText's and add them to this ArrayList.
  When user re-enters, it should keep adding it to the ArrayList.</p>
  
  <p>Objective is to get all the entries from user and show it in a ListView in the next fragment.
  But only the two Strings from the ArrayList into String array for the use as datasource for ArrayAdapter.
  So overridden the toSting method in class diarylogs.
  I can see the value from the ArrayList while sysout. 
  <strong>But, once i setListAdapter, the app crashes. Cannot understand what i am doing wrong.</strong></p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>Class MainActivity extends Activity
  
  //Static variable
  public static ArrayList&lt;DiaryLogs&gt; test;
  public static int Monday=0;
  </code></pre>
  
  <p><strong>Class DiaryLogs</strong></p>
  
  <pre><code>public class DiaryLogs {
  
      String timeEntry, entryEntered;
      int day;
  
      // single constructor that takes an integer and two string
      public DiaryLogs(int day, String timeEntry, String entryEntered) {
          super();
          this.day = day;
          this.timeEntry = timeEntry;
          this.entryEntered = entryEntered;
  
      }
  
      public String getTimeEntry() {
          return timeEntry;
      }
  
      public void setTimeEntry(String timeEntry) {
          this.timeEntry = timeEntry;
      }
  
      public String getEntryEntered() {
          return entryEntered;
      }
  
      public void setEntryEntered(String entryEntered) {
          this.entryEntered = entryEntered;
      }
  
      public int getDay() {
          return day;
      }
  
      public void setDay(int day) {
          this.day = day;
      }
  
      @Override
      public String toString() {
  
          return timeEntry + "\n" + entryEntered;
  
  
      }
  }
  </code></pre>
  
  <p><strong>Class Monday_fragment</strong></p>
  
  <pre><code>public class Monday_fragment extends Fragment {
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          return inflater.inflate(R.layout.monday_fragment, container, false);
  
      }
  
      @Override
      public void onViewCreated(View view, Bundle savedInstanceState) {
          currentDateTime();
          super.onViewCreated(view, savedInstanceState);
  
      }
  
      public void currentDateTime() {
          EditText timeText = (EditText) getView().findViewById(
                  R.id.dateTimeEText);
          SimpleDateFormat df = new SimpleDateFormat("d/M/yyyy:H:m");
          String dateTime = df.format(Calendar.getInstance().getTime());
          timeText.setText(dateTime);
      }
  
      @Override
      public void onStart() {
  
          Button saveBtn = (Button) getView()
                  .findViewById(R.id.saveDiaryEntryBtn);
          saveBtn.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
  
                  EditText timeText = (EditText) getView().findViewById(
                          R.id.dateTimeEText);
  
                  EditText entryText = (EditText) getView().findViewById(
                          R.id.diaryEntryEText);
                  String timeEntry = timeText.getText().toString();
  
                  String entryEntered = entryText.getText().toString();
  
                  MainActivity.test = new ArrayList&lt;DiaryLogs&gt;();
  
                  MainActivity.test.add(new DiaryLogs(MainActivity.Monday,
                          timeEntry, entryEntered));
  
              }
  
          }
  
          );
  
          Button showBtn = (Button) getView().findViewById(
                  R.id.showDiaryEntriesBtn);
          showBtn.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  FragmentManager fragmentManager = getFragmentManager();
                  FragmentTransaction fragmentTransaction = fragmentManager
                          .beginTransaction();
                  Monday_list_fragment mlf = new Monday_list_fragment();
                  fragmentTransaction.replace(android.R.id.content, mlf);
                  fragmentTransaction.commit();
  
              }
          });
  
          super.onStart();
      }
  
  }
  </code></pre>
  
  <p><strong>Class Monday_list_fragment</strong></p>
  
  <pre><code>public class Monday_list_fragment extends ListFragment {
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // TODO Auto-generated method stub
  
          return inflater
                  .inflate(R.layout.monday_list_fragment, container, false);
  
      }
  
      @Override
      public void onViewCreated(View view, Bundle savedInstanceState) {
  
          super.onViewCreated(view, savedInstanceState);
  
  
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
  System.out.println(MainActivity.test); //test: if value can be seen
  
          ArrayAdapter&lt;DiaryLogs&gt; arrayAdapter = new ArrayAdapter&lt;DiaryLogs&gt;(
                  getActivity(), 
                  android.R.layout.simple_list_item_1, MainActivity.test
                  );
          setListAdapter(arrayAdapter); //once i set adapter it crashes
  
      }
  
  }
  </code></pre>
  
  <p><strong>layout XML file: monday_list_fragment.xml</strong></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="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;ListView
          android:id="@id/android:list"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:smoothScrollbar="true" &gt;
      &lt;/ListView&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true" &gt;
  
          &lt;Button
              android:id="@+id/returnBtn"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/return_mon_Btn" 
              android:onClick="monClick"&gt;
          &lt;/Button&gt;
      &lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>LOGCAT</strong></p>
  
  <pre><code>04-11 23:45:53.992: E/AndroidRuntime(10006): FATAL EXCEPTION: main
  04-11 23:45:53.992: E/AndroidRuntime(10006): Process: com.example.s0217980_diary, PID: 10006
  04-11 23:45:53.992: E/AndroidRuntime(10006): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.s0217980_diary/com.example.s0217980_diary.MainActivity}: android.view.InflateException: Binary XML file line #41: Error inflating class fragment
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.os.Handler.dispatchMessage(Handler.java:102)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.os.Looper.loop(Looper.java:136)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.ActivityThread.main(ActivityThread.java:5017)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at java.lang.reflect.Method.invoke(Method.java:515)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at dalvik.system.NativeStart.main(Native Method)
  04-11 23:45:53.992: E/AndroidRuntime(10006): Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class fragment
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.Activity.setContentView(Activity.java:1929)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at com.example.s0217980_diary.MainActivity.onCreate(MainActivity.java:52)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.Activity.performCreate(Activity.java:5231)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    ... 11 more
  04-11 23:45:53.992: E/AndroidRuntime(10006): Caused by: java.lang.NullPointerException
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at com.example.s0217980_diary.Monday_list_fragment.onCreate(Monday_list_fragment.java:45)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.Fragment.performCreate(Fragment.java:1678)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:859)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.app.Activity.onCreateView(Activity.java:4786)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
  04-11 23:45:53.992: E/AndroidRuntime(10006):    ... 21 more
  04-11 23:48:11.294: D/dalvikvm(10069): GC_FOR_ALLOC freed 71K, 6% free 3267K/3448K, paused 16ms, total 24ms
  04-11 23:48:11.364: D/AndroidRuntime(10069): Shutting down VM
  04-11 23:48:11.364: W/dalvikvm(10069): threadid=1: thread exiting with uncaught exception (group=0xb0c9db20)
  04-11 23:48:11.374: E/AndroidRuntime(10069): FATAL EXCEPTION: main
  04-11 23:48:11.374: E/AndroidRuntime(10069): Process: com.example.s0217980_diary, PID: 10069
  04-11 23:48:11.374: E/AndroidRuntime(10069): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.s0217980_diary/com.example.s0217980_diary.MainActivity}: android.view.InflateException: Binary XML file line #41: Error inflating class fragment
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.os.Handler.dispatchMessage(Handler.java:102)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.os.Looper.loop(Looper.java:136)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.ActivityThread.main(ActivityThread.java:5017)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at java.lang.reflect.Method.invoke(Method.java:515)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at dalvik.system.NativeStart.main(Native Method)
  04-11 23:48:11.374: E/AndroidRuntime(10069): Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class fragment
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.Activity.setContentView(Activity.java:1929)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at com.example.s0217980_diary.MainActivity.onCreate(MainActivity.java:52)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.Activity.performCreate(Activity.java:5231)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    ... 11 more
  04-11 23:48:11.374: E/AndroidRuntime(10069): Caused by: java.lang.NullPointerException
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at com.example.s0217980_diary.Monday_list_fragment.onCreate(Monday_list_fragment.java:45)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.Fragment.performCreate(Fragment.java:1678)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:859)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.app.Activity.onCreateView(Activity.java:4786)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
  04-11 23:48:11.374: E/AndroidRuntime(10069):    ... 21 more
  </code></pre>