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 Android Data Persistence Introduction to Data Persistence Using EditText Data

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Hi, can someone show me what to do here? Thanks!

Time for a quick review! Below we are accessing an EditText and a TextView. We have accessed the actual controls, but lets now set the TextView's contents with whatever is in the EditText.

CodeChallenge.java
EditText entryField = (EditText)findViewById(R.id.entry_field);
TextView textHolder = (TextView)findViewById(R.id.text_holder);

8 Answers

Ben Wong
Ben Wong
19,426 Points

String text = entryField.getText().toString(); textHolder.setText(text);

Kunal Bhuwalka
Kunal Bhuwalka
34,622 Points

What you have to do is First obtain the String from your EditText. After that you have to set the text in your TextView with the string you previously obtained. Here is the code implementation: String text = entryField.getText().toString(); //Obtain the string from EditText and store it in text textHolder.setText(text); //Pass the text to TextView

Anthony Attard
Anthony Attard
43,915 Points

Do it in 1 line textHolder.setText(entryField.getText().toString());

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Hi Kunal, It still doesn't work, i don't know what to do.. Thanks for your help in advance!

Kunal Bhuwalka
Kunal Bhuwalka
34,622 Points

Zubeyr, I tried running this code for the challenge you are on and it worked for me. What error are you facing?

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

This pops up when i try the code.. "Bummer! java.lang.NullPointerException (Look around JavaTester.java line 64)"

Kunal Bhuwalka
Kunal Bhuwalka
34,622 Points

Please copy your entire code here, I will try my best to help although I may not be able to.

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Hi Ben, tnx for the help, though i passed this challenge a few days ago :) Thanks anyways..