Results 1 to 14 of 14
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Need help with a piece of code

  1. #1
    sneeak is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default Need help with a piece of code

    I have my if statement within my button im getting errors saying this.

    I:\Property Manager\PropertyManager.java:138: error: illegal start of expression
    else if(propList.get(i).getdate().indexOf(searchString) != -1))
    ^
    I:\Property Manager\PropertyManager.java:145: error: 'else' without 'if'
    else if(propList.get(i).getAddress().indexOf(searchStri ng) != -1))
    ^
    I:\Property Manager\PropertyManager.java:145: error: illegal start of expression
    else if(propList.get(i).getAddress().indexOf(searchStri ng) != -1))
    ^
    3 errors

    Tool completed with exit code 1

    I am pretty sure I have the If statement correct anyone can figure out what is wrong?


    Java Code:
    button1.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent e)
    			{
    
    				String searchString = textfield1.getText();
    
    				textArea2.setText("");
    
    				int resultsFound = 0;
    
    				//Searching for results
    				for(int i = 0; i < propList.size(); i++)
    				{
    					//indexOf has been used instead of compareTo for it searches within strings
    					//Check for result in paperID
    					if ((Integer.toString(propList.get(i).getPropertyNumber()).indexOf(searchString) != -1))
    					{
    						textArea.append(propList.get(i).toString());
    						resultsFound = resultsFound + 1;
    					}
    
    					//Check for result in topic
    					else if(propList.get(i).getStatus().indexOf(searchString) != -1)
    					{
    						textArea.append(propList.get(i).toString());
    						resultsFound = resultsFound + 1;
    					}
    
    					//Check for result in campus
    					else if(propList.get(i).getPropertyOwner().indexOf(searchString) != -1)
    					{
    						textArea.append(propList.get(i).toString());
    						resultsFound = resultsFound + 1;
    					}
    
    					//Check for result in results
    					else if(propList.get(i).getdate().indexOf(searchString) != -1))
    					{
    						textArea.append(propList.get(i).toString());
    						resultsFound = resultsFound + 1;
    					}
    
    					//Check for result in results
    					else if(propList.get(i).getAddress().indexOf(searchString) != -1))
    					{
    						textArea.append(propList.get(i).toString());
    						resultsFound = resultsFound + 1;
    					}
    				}
    
    				//No reults found
    				if(resultsFound == 0)
    				{
    					textArea2.setText("No results found");
    				}
    
    				//Results found
    				else
    				{
    					 textArea2.setText(resultsFound + " results found for '" + searchString + "' \n\n" + textArea2.getText());
    		  		}
    
    
    			}
    		});

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Java Code:
    else if(propList.get(i).getdate().indexOf(searchString) != -1))
           1            2 1        21        2            1      0-1
    Unbalanced parentheses. If you count them with ( incrementing the count and ) decrementing it, you should reach zero in a balanced expression. This line seems to have an extra ).

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default

    Count your opening and closing parentheses.

    db

    edit

  5. #5
    go4soumya is offline Member
    Join Date
    Oct 2010
    Posts
    32
    Rep Power
    0

    Default

    the syntax should be
    IF
    ELSE IF....(n number of times)
    ELSE....at the end...

    As far as I think, your error message is due the else you didn't provide for the IF just after the for loop. So give an ELSE at the end of all "ELSE IF"s and try. Hope this solves the problem. If not, come back again...we'll see

    Good luck :)

  6. #6
    sneeak is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default

    Cool Thanks guys appreciate the help.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote Originally Posted by go4soumya View Post
    the syntax should be
    IF
    ELSE IF....(n number of times)
    ELSE....at the end...
    In fact, there's no requirement for an "else" at the end. After all the result of a long if/else-if/else-if/... can be to do nothing at all when none of the conditions are true.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,449
    Blog Entries
    7
    Rep Power
    20

    Default

    It's going to be a close finish ladies and gentlemen, the three runners are approaching the finish line very close together and, is it going to be Pbrockway2, Fubarable or Darryl Burke; the runners are struggling and, yes! Ladies and gentlemen, Pbrockway pushed the "Submit Reply" button first, immediately followed by Fubarable and Darryl Burke finishes as a close third! What a terrific race that was!

    kindest regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    sneeak is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    It's going to be a close finish ladies and gentlemen, the three runners are approaching the finish line very close together and, is it going to be Pbrockway2, Fubarable or Darryl Burke; the runners are struggling and, yes! Ladies and gentlemen, Pbrockway pushed the "Submit Reply" button first, immediately followed by Fubarable and Darryl Burke finishes as a close third! What a terrific race that was!

    kindest regards,

    Jos ;-)
    ha ha ha ha ha , must admit i got a laugh out of that JosAH.

    +1
    Last edited by sneeak; 08-24-2011 at 08:46 AM. Reason: Wrong quote.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JosAH View Post
    It's going to be a close finish ladies and gentlemen, the three runners are approaching the finish line very close together and, is it going to be Pbrockway2, Fubarable or Darryl Burke; the runners are struggling and, yes! Ladies and gentlemen, Pbrockway pushed the "Submit Reply" button first, immediately followed by Fubarable and Darryl Burke finishes as a close third! What a terrific race that was!

    kindest regards,

    Jos ;-)
    one horse, go4soumya, was going the wrong way.
    DarrylBurke likes this.

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default

    Quote Originally Posted by JosAH View Post
    It's going to be a close finish ladies and gentlemen, the three runners are approaching the finish line very close together and, is it going to be Pbrockway2, Fubarable or Darryl Burke; the runners are struggling and, yes! Ladies and gentlemen, Pbrockway pushed the "Submit Reply" button first, immediately followed by Fubarable and Darryl Burke finishes as a close third! What a terrific race that was!

    kindest regards,

    Jos ;-)
    Java Code:
    Jos ;-)
          ^ illegal start of expresstion

  12. #12
    go4soumya is offline Member
    Join Date
    Oct 2010
    Posts
    32
    Rep Power
    0

    Default

    newbie in the race...so just lost the track :D
    and thanks pbrockway2, I got to learn from my own mistake.. ;)

  13. #13
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Well at least you ran! Where was Jos, who has been known on occasions to bring up the rear in such events? In the commentator's box! Oh well, I guess it must be well after grolsch o'clock in the Netherlands...

    [Edit] Well I stuffed that up. It's well after that time *here*. So it must be pre-coffee and smoke time in the trailing part of the world.

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,449
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by pbrockway2 View Post
    Well at least you ran! Where was Jos, who has been known on occasions to bring up the rear in such events? In the commentator's box! Oh well, I guess it must be well after grolsch o'clock in the Netherlands...

    [Edit] Well I stuffed that up. It's well after that time *here*. So it must be pre-coffee and smoke time in the trailing part of the world.
    The 'trailing part of the world'? May I remind you sir that the SGT (Standard Grolsch Time) meridian runs exactly through my village (exactly through my back garden aamof) so it is the center of the universe; all planets and other rubbish rotate around this center in very funny orbits. It is 18:00AG (SGT time zone) so six more hours until the pops of the ceramic tops can be heard all over the place; in the mean time it's espresso time and tobacco time indeed.

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Working out chess piece location / piece name
    By danborgir in forum New To Java
    Replies: 5
    Last Post: 04-20-2011, 10:14 AM
  2. Can someone clarify this piece of code for me.
    By DavidPynes in forum New To Java
    Replies: 2
    Last Post: 04-17-2011, 10:22 AM
  3. Code to check if a piece of code is legal.
    By vahshir in forum New To Java
    Replies: 3
    Last Post: 08-30-2010, 04:21 AM
  4. small piece of code: cannot set a max
    By senca in forum New To Java
    Replies: 1
    Last Post: 03-06-2010, 08:26 PM
  5. Decode this piece of Code
    By mikeyl62 in forum New To Java
    Replies: 2
    Last Post: 02-27-2010, 08:59 PM

Posting Permissions

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