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.

A Chatterjee
1,701 PointsI am getting a java.lang.reflect.InvocationTargetException when trying to return a substring of a String object
Java Objects last challenge, step 2 of 2 asks to return the remaining characters from a "Tweet". Can't seem to find the bug. Any pointers?
public class Tweet {
private String mText;
public static final int MAX_NUM_CHARS = 140;
public Tweet(String text) {
mText = text;
}
public String getText() {
return mText;
}
public String getCharsAvail(){
int txtLength = 0;
txtLength = mText.length() - MAX_NUM_CHARS;
return mText.substring (0,txtLength);
}
}
1 Answer

Simon Coates
28,692 PointsFollowing seems to pass challenge
public int getCharsAvail(){
return Tweet.MAX_NUM_CHARS - mText.length();
}
A Chatterjee
1,701 PointsA Chatterjee
1,701 PointsNever mind! I realized that this is asking to return the remaining length of the text. The way the question was worded I thought it was asking to return the remaining characters...