title: Get User By User Email From SQLite
body: <p>Here's my getUser mothod :</p>
  
  <pre><code>public User getUser(String Email) {
  
      SQLiteDatabase db = this.getReadableDatabase();
  
  
      String sql = "SELECT * FROM " + DBContract.Users.TABLE_NAME
              + " WHERE " + DBContract.Users.COL_EMAIL + " = " + Email;
      try {
          Cursor cursor = db.rawQuery(sql, null);
  
          User user = new User();
  
          // Read data, I simplify cursor in one line
          if (cursor != null) {
              cursor.moveToFirst();
  
              // Get imageData in byte[]. Easy, right?
              user.setUserID(Integer.parseInt(cursor.getString(cursor.getColumnIndex(DBContract.Users._ID))));
              user.setUserName(cursor.getString(cursor.getColumnIndex(DBContract.Users.COL_NAME)));
              user.setUserImage(cursor.getBlob(cursor.getColumnIndex(DBContract.Users.COL_IMAGE)));
              user.setUserPassword(cursor.getString(cursor.getColumnIndex(DBContract.Users.COL_PASSWORD)));
              user.setUserEmail(cursor.getString(cursor.getColumnIndex(DBContract.Users.COL_EMAIL)));
              user.setUserLocation(cursor.getString(cursor.getColumnIndex(DBContract.Users.COL_LOCATION)));
  
  
          }
          cursor.close();
          db.close();
          return user;
  
      } catch (SQLException e) {
  
      }
      return null;
  }
  </code></pre>
  
  <p>User Profile Fragment where i call the getUser:</p>
  
  <pre><code>public class UserHomeFragment extends Fragment {
  DBHelper dbHelper;
  User user;
  ImageView userImageView;
  TextView userNameTexView;
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.user_profile_home_fragment, container, false);
  
      dbHelper = new DBHelper(v.getContext());
      user = new User();
      userImageView = (ImageView) v.findViewById(R.id.userimg);
      userNameTexView = (TextView) v.findViewById(R.id.user_name);
  
  
      Bundle extras = getActivity().getIntent().getExtras();
      assert extras != null;
      String userEmail = extras.getString("userEmail");
  
  
      user = dbHelper.getUser(userEmail);
  
    // Bitmap bitmap = BitmapFactory.decodeByteArray(userImage, 0, userImage.length);
    // userImageView.setImageBitmap(bitmap);
     userNameTexView.setText(user.getUserName());
  
      return v;
  }}
  </code></pre>
  
  <p>Why the getUser return null ? I've checked there are users at the user's table .</p>
  
  <p>Error Massage:Attempt to invoke virtual method 'java.lang.String com.arfni.ayafinal.model.User.getUserName()' on a null object reference</p>