2

I have a class named "note" which provides a note with a title, a note, and a color. I save all the notes in a SQLite database. BDDManager is my SQLite database manager it inserts, removes etc... notes from database.

    private void readNotes(){
    Note note = new Note();

    BDDManager.open();

    note = BDDManager.getNoteWithTitle("Title");

    if(note != null && note.getTitle() == "Title"){

        addCardNote(note);
        Toast toast = Toast.makeText(this, note.getCouleur(), Toast.LENGTH_LONG);
        toast.show();

    }

    BDDManager.close();
}

In this part of the code, if I don't remove "note.getTitle()=="Title"" it doesn't work. And all the strings from my database are not equal to what they are supposed to be equal

Pumpkin
  • 319
  • 2
  • 3
  • 11
  • 2
    Compare strings with `String`'s `equals` method, not with `==`. – rgettman Oct 12 '13 at 00:20
  • Ok this problem is solved, thanks rgettman – Pumpkin Oct 12 '13 at 00:24
  • My true problem is this one: I get the color of the note and then send it to a class wich is supposed to create a note with the color given, but it doesn't work – Pumpkin Oct 12 '13 at 00:24
  • `==` compare the reference for the `String` Object if they are referenced to the same Object then returned `true` regarding of what is the value for each one, but when you use `equal()` method the value will be compared, **NOT** the reference for `String` Object !! – Husam Oct 12 '13 at 00:25
  • 1
    Ok thanks everyone, I will use equal() to set the color, I was using == for it, thanks ! Problem solved ! – Pumpkin Oct 12 '13 at 00:29

1 Answers1

1

Instead of

if(note != null && note.getTitle() == "Title"){

You should try

if(note != null && note.getTitle().equals("Title")){
jbihan
  • 3,053
  • 2
  • 24
  • 34