Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Delivering the MVP Validation

*[SOLVED]* My code won't run! Need a coding expert! :(

Hi there : )

I've looked through the questions posted here and searched online, but am still struggling to figure out why my code from the challenge will not compile. Would love some assistance. Thank you for the help!! Love the course!

What I have (tried to format here as best I could):

public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {
    boolean isValidFieldName = false; 
    while (isValidFieldName != true) {
      if (fieldName.charAt(0) == 'm' && Character.isUpperCase(fieldName.charAt(1))) {
        isValidFieldName = true;
      } throw new IllegalArgumentException("Please insert either an 'm' before your field name, or capitalize the first letter of your name.");
    }
    return fieldName;
  }
}

Moderator Edited: Added "Solved" to Post title as a resolution has been reached.

Sorry for taking your time if you read my query. I actually figured it out! I needed an else statement. :D

Even though the question is solve I would like to add a couple of thing so the students that read this code don't get confuse.

  1. In the if statement line you want to use || instead of &&, because you want to throw and IllegalArgumentException if any of the factors are true, not only both.
  2. You also want to change the value of isValidFieldName to true if there is no IllegalArgumentException, otherwise you will be in a loop because isValidFieldName will always be false.