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

Compiler error but nothing in preview. Code works in repl.

Each time I try this I get a compiler error, but switching to the preview window doesn't contain any text. The code works if I try it in workspaces under java-repl. Anyone?

TeacherAssistant.java
public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {
   private boolean isMember = fieldName.charAt(0) == 'm';
   private boolean isCamelCase = Character.isUpperCase(fieldName.charAt(1));
    if (!isMember || !isCamelCase) {
      throw new IllegalArgumentException("Field name must comform to guidelines."); 
    }
    return fieldName;
  }

}

5 Answers

Realized I left part of this out....after numerous attempts to figure this out, it also gives me a "lost communication with server" error and I have to reload the challenge - three times thus far.

Though I don't have the answer, I did have the same issues yesterday. The communication problem happens in all three browsers: IE, Chrome, and Firefox. It seems to be a bug, possibly related to scrolling the window the challenge is on. That was on the For Each challenge.

Today, I have no communication issue bug, but I do have no error code with the TeacherAssistant challenge. So far, I have this same error in IE and Firefox. This no error code issue has dogged me since I started the MVP, third section of Java Objects. It only happens at times.

public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {
    // These things should be verified:
    // 1.  Member fields must start with an 'm'
    if (fieldName.charAt(0) != 'm') {
     throw  new IllegalArgumentException(fieldName + "does not start with an m");
    }
    // 2.  The second letter in the field name must be uppercased to ensure camel-casing
    char secondLetter = fieldName.charAt(1);
    if (! secondLetter.isUpperCase()) {
     throw new IllegalArgumentException(fieldName + "is not camel case"); 
    }
    // NOTE:  To check if something is not equal use the != symbol. eg: 3 != 4
    return fieldName;
  }

}

I guess it should work, but it doesn't pass. Neither will it show error code.

If one were to run this challenge without adding to the original code, they would get a blank error code screen with a header which says, "Expected "firstName" to fail but it passed". This might be a helpful clue, but "firstName" is not in the code originally, just "fieldname" is. So, my question is, should I substitute the fieldname parameter for another inside the code of the class?

Craig Dennis
Craig Dennis
Treehouse Teacher

Hey David!

Can you start a new thread with this question please? I want to provide the answer, I just don't want it buried in this little corner we've found created ;)

Thanks!

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Try losing those private keywords. On my phone so I can't test it at the moment. Let me know!

Eliminating the private tags seems to have worked. Any idea why?

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

They belong at the class level, doesn't really make sense at the method level. I've never done that before, but I'd assume it would throw a compiler error. Might be a version thing...8 in workspaces, 7 in code challenges. Still on phone, will check!

Fair enough. To be honest the more confusing issue was that it threw a compiler error, but there was no error information in the preview, so nothing to go on for troubleshooting. In any case, that fixed it. Thanks.

Craig Dennis
Craig Dennis
Treehouse Teacher

Thanks for pointing out the bug! I'll get it sorted!