Building Android Apps on Java

Hello, I got stuck with the below article.
https://www.codecademy.com/paths/introduction-to-android-with-java/tracks/developing-an-android-application/modules/building-android-apps/articles/editing-layouts-in-text-mode

I watched the video until it instructed me to create an androidx.constraintlayout.widget.constraintlayout. As I tried to add it into the root element of new resource file, it displays no option or no suggestion to do so.

Any advice for me?

Try just having androidx as the root. Also, if that doesn’t work, there should already be the code for a constraint layout in activity_main.XML.

I have more question - the androidx as the root seems to have worked, I haven’t seen any errors popping up on my Android Studio.

However, when I open the card_main file, I can’t see the androidx.constraintlayout.widget.constraintlayout. The lesson video has it on the card file it created for the Unquote project.


As you mentioned, the androidx.constraintlayout.widget.constraintlayout code is in activity_main.XML .

. The video suggests that I add xmlns: tools="http://schemas.android.com/tools into the card_main. Shall I add it to activity_main.XML as it has androidx.constraintlayout.widget.constraintlayout in it?

No, it has to be added to the contact_card file. I think it’s a placeholder image, so it wouldn’t make sense to put it into activity_main. Can you post a screenshot of how you created business_card.XML? Also, worst comes to the worst, you can always copy the relevant code from activity_main into business_card (the constraint layout code).

So this is how I created business_card.XML

As suggested, I copied the relevant code from activity_main into business_card

Still the error persists

I actually don’t know what to do with this.

The starting one is missing a > but that won’t be what’s causing the main error.


I’ll get back to you if I find out more.

@codeneutrino Have you found anything? I’ve tried to redo this step but to no avail.

I recoded the contact_card_main.xml as follows

And this error came out

Hmm. I’m not sure you can use constraints with Linearlayouts. Could you post the code itself into the forums, so I can play with it?

Thank you for the response @codeneutrino . I actually ended up changing from linearLayout to androidx.constraintlayout.widget.ConstraintLayout . Then I transferred all the codes from contact_card_main to activity_main . After the transfer, I deleted the contact_card_main. It seemed to work for me.

1 Like