Results 1 to 3 of 3
Thread: if-statement issue.
- 10-11-2012, 02:53 PM #1
Alternative Nerd
- Join Date
- Oct 2012
- Location
- Denmark
- Posts
- 2
- Rep Power
- 0
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:
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: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 + "." } }
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!Java Code:if (nr == 0) { code omitted }
-qiTsuk
- 10-11-2012, 02:59 PM #2
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
- 10-11-2012, 03:14 PM #3
Alternative Nerd
- Join Date
- Oct 2012
- Location
- Denmark
- Posts
- 2
- Rep Power
- 0
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
-
the switch statement and unreachable statement error
By name in forum New To JavaReplies: 2Last Post: 03-26-2012, 04:27 PM -
IF statement issue
By AndreaRenee in forum New To JavaReplies: 15Last Post: 03-11-2012, 05:55 AM -
"If statement" issue
By jdm113497 in forum New To JavaReplies: 10Last Post: 04-13-2011, 12:39 AM -
Issue with deployment script when if statement/filter not valid
By pi4r0n in forum New To JavaReplies: 4Last Post: 02-25-2011, 02:28 PM -
issue with update on table and prepared statement
By hacktorious in forum JDBCReplies: 1Last Post: 01-10-2011, 01:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks