title: Cursor query returning 0
body: <p>I am building an application with database but a problem arises when I am retrieving the values from the database it returns empty (i.e. returned cursor has 0 tuples) and I am sure that database contains some information into it.
  I am providing my code please help if you noticed any error.</p>
  
  <p>Fragment where user inputs data to database:</p>
  
  <pre><code>    public class FCar extends Fragment implements AdapterView.OnItemSelectedListener {
  
      public FCar() {
      }
  
      CarDataBaseAdapter carDataBaseAdapter;
      SessionManagement session;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
  //        inflating the view
          final View rootView = inflater.inflate(R.layout.fragment_car, container, false);
  //        declaring stuff, not sure why it has to be final
          final Spinner carSpinner;
          final EditText editTextDistance, editTextMin;
          Button btnSubmitCar;
  
  //      create new car database
          carDataBaseAdapter = new CarDataBaseAdapter(getActivity());
          carDataBaseAdapter = carDataBaseAdapter.open();
          SQLiteDatabase x = carDataBaseAdapter.getDatabaseInstance();
  
          session = new SessionManagement(getActivity().getApplicationContext());
  
  //        display existing tables
  /*
          Cursor hi = x.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
          hi.moveToFirst();
          int f = hi.getCount();
          String g = Integer.toString(f);
          Toast.makeText(getActivity().getApplicationContext(), g, Toast.LENGTH_LONG).show();
          while ( !hi.isAfterLast() ) {
              String h = (hi.getString( hi.getColumnIndex("name")) );
              hi.moveToNext();
              Toast.makeText(getActivity().getApplicationContext(), h, Toast.LENGTH_LONG).show();
          }
  */
  
          // Get References of Views
          carSpinner = (Spinner) rootView.findViewById(R.id.spinner_car_type);
          editTextDistance = (EditText) rootView.findViewById(R.id.editTextcarDistance);
          editTextMin = (EditText) rootView.findViewById(R.id.editTextcarMin);
  
          // Spinner click listener
          carSpinner.setOnItemSelectedListener(this);
  
  //        set default spinner selection
          carSpinner.setSelection(0);
  
          // Spinner Drop down elements
          List&lt;String&gt; categories = new ArrayList&lt;&gt;();
          categories.add("Standard");
          categories.add("Truck");
          categories.add("Electric/Hybrid");
  
          // Creating adapter for spinner
          ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;&gt;(getActivity(), android.R.layout.simple_spinner_item, categories);
  
          // Drop down layout style - list view with radio button
          dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
          // attaching data adapter to spinner
          carSpinner.setAdapter(dataAdapter);
  
  //      identifying the button
          btnSubmitCar = (Button) rootView.findViewById(R.id.button_car_submit);
          btnSubmitCar.setOnClickListener(new View.OnClickListener() {
  
                                              public void onClick(View v) {
  
  //              take username entry from login / sign up form via method in FProfile
  //                String currentUser = getSingleEntry();
                                                  String username = session.getUsername();
  
                                                  SimpleDateFormat formata = new SimpleDateFormat("MM/dd/yyyy", Locale.CANADA);
                                                  String date = formata.format(new Date());
  
                                                  String type = carSpinner.getSelectedItem().toString();
  
  //                convert distance to integer
                                                  int distance = 0;
                                                  try {
                                                      distance = Integer.parseInt(editTextDistance.getText().toString());
                                                  } catch (NumberFormatException nfe) {
                                                      System.out.println("Could not parse distance " + nfe);
                                                  }
  //                convert minutes to integer
                                                  int time = 0;
                                                  try {
                                                      time = Integer.parseInt(editTextMin.getText().toString());
                                                  } catch (NumberFormatException nfe) {
                                                      System.out.println("Could not parse minutes" + nfe);
                                                  }
  
                                                  // Save the Data in Database
                                                  carDataBaseAdapter.insertEntry(username, date, type, distance, time);
  //                                              link back to input menu
                                                  Intent intent = new Intent(getActivity(), MainActivity.class);
  
                                                  intent.putExtra("caller", "Input");
                                                  startActivity(intent);
  
                                              }
                                          }
          );
          return rootView;
      }
  </code></pre>
  
  <p>This is my query:</p>
  
  <pre><code>public Cursor getCarEntry(String username, String Day, String Type) {
  
      Cursor carCursor = db.query(true, "CAR", new String[]{"distance, time"}, "USERNAME=? AND DATE=? AND TYPE=?", new String[]{username, Day, Type}, null, null, null, "50");
      if (carCursor.getCount() &lt; 1) {
          carCursor.close();
      }
          carCursor.moveToFirst();
          for (int i = 0; i &lt; carCursor.getCount(); i++) {
              int distance = carCursor.getInt(carCursor.getColumnIndex("DISTANCE"));
              int time = carCursor.getInt(carCursor.getColumnIndex("TIME"));
          }
          return carCursor;
  </code></pre>
  
  <p>Then I retrieve it in a fragment</p>
  
  <pre><code>            carStandardCursors[i] = carDataBaseAdapter.getCarEntry(currentUsername, searchDate, "Standard");
  </code></pre>
  
  <p>Then I made a loop to perform math on the cursors</p>
  
  <pre><code>        for (int i = 0; i &lt; 7; i++) {
          Cursor ccursor = carStandardCursors[i];
          carStandardTotal = CalculateCarStandard(ccursor);
          carStandard[dex] = carStandardTotal;
  </code></pre>
  
  <p>And I found that the values in carStandardCursors[i] were all zero.</p>