Results 1 to 3 of 3
  1. #1
    qiTsuk is offline Alternative Nerd
    Join Date
    Oct 2012
    Location
    Denmark
    Posts
    2
    Rep Power
    0

    Angry if-statement issue.

    So, I am writing a simple notebook program, with a GUI... The notebook uses ArrayList to save the inputs and everything works fine except for:

    Java Code:
    private void delNoteButActionPerformed(java.awt.event.ActionEvent evt) {                                           
            String nr = nrField.getText();
            int nrT = Integer.parseInt(nr);
            if (nrT < 0 || nrT < notes.nrOfNotes() || nrT > notes.nrOfNotes()) {
              noteDisplay.setText("There is no note stored at note-index\nnr : " + nrT + ".");
              nrField.setText(""); 
            }else {
                notes.delNote(nrT);
                nrField.setText("");
                noteDisplay.setText("You have deleted the note at note-index nr: " + nrT + "." }
            }
    The notes.nrOfNotes()-method is an ArrayList.size()-method call... However... If I try to retrieve a note, I end in the if-sentence. I've also tried adding an:
    Java Code:
    if (nr == 0) {
    code omitted }
    But then it just throws an exception... What am I doing wrong? I don't want someone to just tell me the solution! I need to know why it is not working. Any helt will be greatly appriciated!

    -qiTsuk

  2. #2
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: if-statement issue.

    What is the exception thrown? What was the goal of this if statement? To detect if the user has not entered in any notes? To have the user delete a portion of text from an array of text? I am confused on why you are looking for an integer in your nrField. Isn't it a note? Is it just numbers? Could explain what the purpose of this is so that we can get a better idea on what you should do next.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  3. #3
    qiTsuk is offline Alternative Nerd
    Join Date
    Oct 2012
    Location
    Denmark
    Posts
    2
    Rep Power
    0

    Default Re: if-statement issue.

    Ok.. A little more detail...

    This button is supposed to delete (and I have a similar one that gets notes) the note that lies in the arraylist at a specified number. So the nrField is only meant for numbers. So the idea is if you enter a number that doesn't currently exist in the array, it should give you an error message. Instead, no matter what number you enter right as of right now, it tells me that I have no note stored. Even if I can call another method and see that I have plenty of notes. I can get the button to work, if I remove the if-else statements. But then it does nothing when I enter a number that doesn't exist in the array index...

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2012, 04:27 PM
  2. IF statement issue
    By AndreaRenee in forum New To Java
    Replies: 15
    Last Post: 03-11-2012, 05:55 AM
  3. "If statement" issue
    By jdm113497 in forum New To Java
    Replies: 10
    Last Post: 04-13-2011, 12:39 AM
  4. Replies: 4
    Last Post: 02-25-2011, 02:28 PM
  5. Replies: 1
    Last Post: 01-10-2011, 01:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •