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) User Input Getting Text from an EditText

Nicholas Vitebsky
Nicholas Vitebsky
568 Points

I successfully completed the EditText with the Toast message, but now all of a sudden my image does not show up.

In my .xml file, I have the ImageView coded in, and visually the image is present, but it is not present in the emulator. My code for my MainActivity.java is package com.example.nvite.signalsfrommars;

import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;

public class MainActivity extends Activity {

private EditText mNameField;
private Button mStartButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNameField = (EditText)findViewById(R.id.nameEditText);
    mStartButton = (Button)findViewById(R.id.button);

    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view){
            String name = mNameField.getText().toString();
            Toast.makeText(MainActivity.this, name, Toast.LENGTH_LONG).show();
        }
    });
}

}

Then, my activity-main.xml file's code is:

<?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" tools:context="com.example.nvite.signalsfrommars.MainActivity">

<ImageView
    android:id="@+id/titleImageView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:contentDescription="Signals from Mars"
    android:scaleType="fitXY"
    app:srcCompat="@drawable/main_title"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="16dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/>

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start your adventure!"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="10dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"/>

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

<com.google.android.gms.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/titleImageView"
    android:layout_marginLeft="137dp"
    android:layout_marginStart="137dp"/>

</RelativeLayout>

Thanks!

1 Answer

Seth Kroger
Seth Kroger
56,414 Points

Umm, somehow you got a MapView inserted into the layout that shouldn't be there (at the bottom of the layout file). As I read it the MapView is likely covering the image, so try removing the MapView.

Nicholas Vitebsky
Nicholas Vitebsky
568 Points

Hi Seth, I tried to remove the MapView and it seemed fine in my .xml file, but the image is still not present in the emulator. Are there any more things you recommend trying?