title: Display Data in Fragment in Android
body: <p>I'm trying to display data from SQLite and display it in the listview in fragment.This is my code and when I run it, it closes automatically. This code is inside my main activity</p>
  
  <pre><code>    public static class ListDoctorFragment extends Fragment {
  
      ListView list;
      DataDB data = new DataDB();
  
      ArrayAdapter&lt;String&gt; listAdapter;
  
      public ListDoctorFragment() {
      }
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
              final View view = inflater.inflate(R.layout.listdoctor, container, false);
  
              ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;();
              try {
                  names = data.getDoctorlistDB(getActivity());
              } catch (SQLException e) {
                  e.printStackTrace();
              }
  
              listAdapter = new ArrayAdapter&lt;String&gt;(getActivity(), R.layout.support_simple_spinner_dropdown_item, names);
  
              // set the adapter
              list.setAdapter(listAdapter);
  
              return view;
          }
      }
  </code></pre>