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 trialA 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,694 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...