title: I will read an arraylist created from sqlite to show content in listview but I get an error message
body: <p>The objective is a ListView with all Games from a specific team. How you see, I created a function (<em>getAllGamesByTeam()</em>) in <em>GamesFragment.java</em> to fill a arraylist with all games. Always, when I start this Fragment, I get the <a href="https://i.stack.imgur.com/M30p3.png" rel="nofollow noreferrer">error message</a>:</p>
  <blockquote>
  <p>FATAL EXCEPTION: main Process: vcoach.com, PID: 5881
  java.lang.NullPointerException: Attempt to invoke virtual method 'void
  vcoach.com.SQLiteDB_statistics_tblGame_DataSource.openReadOnly()' on a
  null object reference at
  vcoach.com.GamesFragment.onResume(GamesFragment.java:84)</p>
  </blockquote>
  <p>GamesFragment.java:84 point at line <em>dataSource_tblGame.openReadOnly();</em> in Function <em>onResume()</em>. The last action in Run-Log of Android Studio is open the data source. I really don't know, what could it be and I am depending on your help because I investigated a lot of time to solve this problem myself but without any success.</p>
  <h2>Code</h2>
  <p><strong>GamesFragment.java</strong></p>
  <pre><code>public class GamesFragment extends Fragment{
  
  public static ListView listView_Games;
  
  public static final String LOG_TAG = GamesFragment.class.getSimpleName();
  public static SQLiteDB_statistics_tblGame_DataSource dataSource_tblGame;
  private SQLiteDatabase db_statistics;
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater_games, ViewGroup container, Bundle savedInstanceState) {
      View view_games = inflater_games.inflate(R.layout.fragment_games, container, false);
  
      //Initialize Objects
      listView_Games = (ListView) view_games.findViewById(R.id.listView_Games);
      final FloatingActionButton floatingActionButton_startagame = (FloatingActionButton) view_games.findViewById(R.id.floatingActionButton_startagame);
      final Button button_welcome = (Button) view_games.findViewById(R.id.button_welcome);
  
      //FloatingActionButton floatingActionBbutton_startagame
      floatingActionButton_startagame.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view){
              //Create DialogFragment
              DialogFragment newGameDialog = new NewGameDialog();
              newGameDialog.show(getActivity().getSupportFragmentManager(), &quot;Dialog&quot;);
  
              //Create Bundle and transfer variable gametime to GameActivity
              Bundle toDialog_NewGameDialog = new Bundle();
              newGameDialog.setArguments(toDialog_NewGameDialog);
          }
      });
  
      //Button button_welcome
      button_welcome.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              startActivity(new Intent(getActivity(),WelcomeActivity.class));
          }
      });
  
      return view_games;
  }
  
  public void getAllGamesByTeam(){
      GamesFragment_ListView_Games.arrayList_Games = dataSource_tblGame.getAllGamesByTeam(1);
  
      GamesFragment_ListView_Games.Adapter_ListView_games adapter_ListView_games = new GamesFragment_ListView_Games.Adapter_ListView_games(getActivity(), GamesFragment_ListView_Games.arrayList_Games);
      listView_Games.setAdapter(adapter_ListView_games);
      listView_Games.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
  }
  
  @Override
  public void onResume() {
      super.onResume();
  
      Log.d(LOG_TAG, &quot;Die Datenquelle wird geöffnet.&quot;);
      dataSource_tblGame.openReadOnly();
  
      getAllGamesByTeam();
  }
  
  @Override
  public void onPause() {
      super.onPause();
  
      Log.d(LOG_TAG, &quot;Die Datenquelle wird geschlossen.&quot;);
      dataSource_tblGame.close();
  }
  </code></pre>
  <p><strong>SQLiteDB_statistics_tblGame_DataSource.java</strong></p>
  <pre><code>public class SQLiteDB_statistics_tblGame_DataSource {
  
  private static final String LOG_TAG = SQLiteDB_statistics_Helper.class.getSimpleName();
  
  private SQLiteDatabase db_statistics;
  private SQLiteDB_statistics_Helper db_statistics_helper;
  
  private String[] table_game_columns = {
          SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_ID,
          SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_HOMETEAM_ID,
          SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_GUESTTEAM,
          SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_DATE
  };
  
  public SQLiteDB_statistics_tblGame_DataSource(Context context){
      Log.d(LOG_TAG, &quot;Unsere DataSource erzeugt jetzt den db_statistics_helper.&quot;);
      db_statistics_helper = new SQLiteDB_statistics_Helper(context);
  }
  
  public void open(){
      Log.d(LOG_TAG, &quot;Unsere DataSource erzeugt jetzt den SQLiteDB_statistics_Helper.&quot;);
      db_statistics = db_statistics_helper.getWritableDatabase();
      Log.d(LOG_TAG, &quot;Datenbank-Referenz erhalten. Pfad zur Datenbank: &quot; + db_statistics.getPath());
  }
  
  public void openReadOnly(){
      Log.d(LOG_TAG, &quot;Unsere DataSource erzeugt jetzt den SQLiteDB_statistics_Helper aber nur zum Lesen.&quot;);
      db_statistics = db_statistics_helper.getReadableDatabase();
      Log.d(LOG_TAG, &quot;Datenbank-Referenz erhalten. Pfad zur Datenbank: &quot; + db_statistics.getPath());
  }
  
  public void close(){
      db_statistics_helper.close();
      Log.d(LOG_TAG, &quot;Datenbank mit Hilfe des SQLiteDB_statistics_Helpers geschlossen.&quot;);
  }
  
  //save a game in Table Game
  public SQLiteDB_statistics_tblGame createGame_SQLiteDB_statistics(long hometeam_id, String guestteam, String date){
      open();
  
      ContentValues values_game = new ContentValues();
      values_game.put(SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_HOMETEAM_ID, hometeam_id);
      values_game.put(SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_GUESTTEAM, guestteam);
      values_game.put(SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_DATE, date);
  
      long insertId = db_statistics.insert(SQLiteDB_statistics_Helper.TABLE_GAME, null, values_game);
  
      Cursor cursor = db_statistics.query(SQLiteDB_statistics_Helper.TABLE_GAME, table_game_columns, SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_ID + &quot;=&quot; + insertId, null, null, null, null);
  
      cursor.moveToFirst();
      SQLiteDB_statistics_tblGame sqLiteDB_statistics_tblGame = cursorGame_ToSQLite_statistics(cursor);
      cursor.close();
  
      return sqLiteDB_statistics_tblGame;
  }
  
  public SQLiteDB_statistics_tblGame cursorGame_ToSQLite_statistics(Cursor cursor){
  
      int idIndex = cursor.getColumnIndex(SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_ID);
      int idHometeam_id = cursor.getColumnIndex(SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_HOMETEAM_ID);
      int idGuestteam = cursor.getColumnIndex(SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_GUESTTEAM);
      int idDate = cursor.getColumnIndex(SQLiteDB_statistics_Helper.TABLE_GAME_COLUMN_DATE);
  
      long id = cursor.getLong(idIndex);
      long hometeam_id = cursor.getLong(idHometeam_id);
      String guestteam = cursor.getString(idGuestteam);
      String date = cursor.getString(idDate);
  
      SQLiteDB_statistics_tblGame sqLiteDB_statistics_tblGame = new SQLiteDB_statistics_tblGame(id, hometeam_id, guestteam, date);
  
      return sqLiteDB_statistics_tblGame;
  }
  
  
  /*&lt;!-- Experimental --&gt;*/
  
  public ArrayList&lt;SQLiteDB_statistics_tblGame&gt; getAllGamesByTeam(int hometeam_id) {
      ArrayList&lt;SQLiteDB_statistics_tblGame&gt; arrayList_Games = new ArrayList&lt;SQLiteDB_statistics_tblGame&gt;();
  
      String selectQuery = &quot;SELECT * FROM &quot; + db_statistics_helper.TABLE_GAME
              + &quot; WHERE &quot; + db_statistics_helper.TABLE_GAME + &quot;.&quot; + db_statistics_helper.TABLE_GAME_COLUMN_HOMETEAM_ID + &quot; = &quot; + hometeam_id;
      Log.e(LOG_TAG, selectQuery);
  
      Cursor cursor = db_statistics.rawQuery(selectQuery, null);
  
      if(cursor.moveToFirst()){
          do{
              SQLiteDB_statistics_tblGame sqLiteDB_statistics_tblGame = new SQLiteDB_statistics_tblGame();
              sqLiteDB_statistics_tblGame.setGame_id(cursor.getInt(cursor.getColumnIndex(db_statistics_helper.TABLE_GAME_COLUMN_ID)));
              sqLiteDB_statistics_tblGame.setHometeam_idfs(cursor.getInt(cursor.getColumnIndex(db_statistics_helper.TABLE_GAME_COLUMN_HOMETEAM_ID)));
              sqLiteDB_statistics_tblGame.setGuestteam(cursor.getString(cursor.getColumnIndex(db_statistics_helper.TABLE_GAME_COLUMN_GUESTTEAM)));
              sqLiteDB_statistics_tblGame.setDate(cursor.getString(cursor.getColumnIndex(db_statistics_helper.TABLE_GAME_COLUMN_DATE)));
  
              arrayList_Games.add(sqLiteDB_statistics_tblGame);
  
          }while (cursor.moveToNext());
      }
      return arrayList_Games;
  }
  </code></pre>
  <p><strong>SQLiteDB_statistics_tblGame.java</strong></p>
  <pre><code>public class SQLiteDB_statistics_tblGame {
  
  public long game_id;
  public long hometeam_idfs;
  public String guestteam;
  public String date;
  
  public SQLiteDB_statistics_tblGame(){
  }
  
  public SQLiteDB_statistics_tblGame(long game_id, long hometeam_idfs, String guestteam, String date){
      this.game_id = game_id;
      this.hometeam_idfs = hometeam_idfs;
      this.guestteam = guestteam;
      this.date = date;
  }
  
  public long getGame_id() {
      return game_id;
  }
  
  public void setGame_id(long game_id){
      this.game_id = game_id;
  }
  
  public long getHometeam_idfs() {
      return hometeam_idfs;
  }
  
  public void setHometeam_idfs(long hometeam_idfs){
      this.hometeam_idfs = hometeam_idfs;
  }
  
  public String getGuestteam() {
      return guestteam;
  }
  
  public void setGuestteam(String guestteam){
      this.guestteam = guestteam;
  }
  
  public String getDate() {
      return date;
  }
  
  public void setDate(String date){
      this.date = date;
  }
  </code></pre>
  <p>}</p>