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 trial

Android Build an Interactive Story App (Retired) Finishing the User Interface Creating the Story Layout

Elliott Prendergast
Elliott Prendergast
5,121 Points

Won't let me add an imageView to my layout

Rendering Problems The following classes could not be found: - android.support.design.widget.RelativeLayout (Fix Build Path, Create Class) Tip: Try to build the project.

I keep getting presented with this error and when I try to drag the image view in it doesn't allow me. All help is greatly appreciated.

Elliott Prendergast
Elliott Prendergast
5,121 Points

I have also tried to build the project multiple times but this does not work.

4 Answers

Christiaan Quyn
Christiaan Quyn
14,706 Points

Of-course , here it is

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".ui.MainActivity"
    tools:showIn="@layout/activity_main"
    android:background="@android:color/white">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/titleImageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:src="@drawable/main_title"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
        android:contentDescription="Signals From Mars !"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="START YOUR ADVENTURE"
        android:id="@+id/startButton"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@android:color/white"
        android:textColor="#FF3A8AEC"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:id="@+id/nameEditText"
        android:layout_above="@+id/startButton"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:hint="Enter your name to begin"
        android:maxLength="30"/>


</RelativeLayout>

--

activity_story.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".ui.StoryActivity">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/storyImageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:src="@drawable/page0"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="You deftly land your ship near where the distress signal originated. You didn&apos;t notice anything strange on your fly-by, but there is a cave in front of you. Behind you is an abandoned rover from the early 21st century."
        android:id="@+id/storyTextView"
        android:layout_below="@+id/storyImageView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:paddingTop="15dp"
        android:lineSpacingMultiplier="1.2"
        />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Stop and Investigate"
        android:id="@+id/choiceButton2"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@android:color/white"
        android:textColor="#FF3A8AEC"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Continue Home to To Earth"
        android:id="@+id/choiceButton1"
        android:layout_above="@+id/choiceButton2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@android:color/white"
        android:textColor="#3a8aec"/>
</RelativeLayout>

Hopefully it works , play around with it and edit it - you might have to go back to the design view , image - src and find the image again.

Let me know how it goes !

Elliott Prendergast
Elliott Prendergast
5,121 Points

Wonderful, worked like a charm thank you so much

Christiaan Quyn
Christiaan Quyn
14,706 Points

Hi Elliot , yes I figured it out - what happened was for some reason Android had loaded some sort of Custom Layout instead of Relative Layout and I just couldnt drag anything on to Custom Layout - I'm also a beginner haha so everything new was confusing me. I switched to xml code view and commented out all the existing code (not deleted incase I needed , but I didnt) and then copy / pasted the xml code from the mainActivity. I ended up editing it a bit and taking out some stuff but it worked - I got my relativeLayout back and could drag things onto it again.

I've got to open up Android Studio to give you in exact detail what I did (I'll try my best to remember) , but let me know if this helped before I do first .

Elliott Prendergast
Elliott Prendergast
5,121 Points

Hi Chistiaan,

Thanks for your help. Unfortunately, android studio has loaded the custom layout to both my story and main activity therefore when I pasted the code in it was the same. If possible could I have a sample of the code you used? Would be of great help. Thanks.

Elliott.

Christiaan Quyn
Christiaan Quyn
14,706 Points

I've got the same problem here :(

Elliott Prendergast
Elliott Prendergast
5,121 Points

Any ideas? It is stopping my whole progress.

Christiaan Quyn
Christiaan Quyn
14,706 Points

Happy to have helped bud, the kind community on the forum has been a life saver during my learning here on treehouse.