Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.