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 trialJ Smillie
39,714 PointsIn the latest version of Android Studio when replicating what Ben is doing here I get a FATAL EXCEPTION
In this line of code:
mSignUpTextView = (TextView)findViewById(R.id.signUpText);
what does log cat mean when it tells me that .RelativeLAyout cannot be cast to android.widget.TextView?
This is part of the error message:
Caused by: java.lang.ClassCastException:
android.widget.RelativeLayout cannot be cast to
android.widget.TextView
at com.wolfonmoon.howl.LoginActivity.onCreate(LoginActivity.java:22)
J Smillie
39,714 Pointssure. here is all the code I have edited alongside the video. Line 22 is the first one inside onCreate that begins with mSignUpTextView
protected TextView mSignUpTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mSignUpTextView = (TextView)findViewById(R.id.signUpText);
mSignUpTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(LoginActivity.this, SignUpActivity.class);
startActivity(intent);
}
});
}
The whole line to the right of '=' is underlined in red and when I hover it says "Unexpected cast to TextView: Layout tag was RelativeLayout"
Gloria Dwomoh
13,116 PointsAll right, can you also post from your XML file the item with id called signUpText?
J Smillie
39,714 Pointssure this is the TextView:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signUp"
android:id="@+id/signUpText"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Gloria Dwomoh
13,116 PointsTry to clean the gradle and run it again, if that doesn't work check if you have set an id on RelativeLayout above and let me know (also post your full XML if possible).
J Smillie
39,714 PointsThanks Gloria. I tried cleaning the project and even rebuilding but the error is still present. Just checked for an id in RelativeLayout and it seems I have assigned signUpText to RelativeLayout. I have no idea why I did this. But thank you so much for your help and fast responses!! Would have taken me much longer on my own
Gloria Dwomoh
13,116 PointsLOL yeah that's the problem then, you used the same id that's why I asked you to tell me if you have added an id there because I suspected that. You are welcome.
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsCan you show us line 22 from your LoginActivity.java file, also what have you defined "mSignUpTextView" to be?