Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:03:39+00:00 2026-05-29T08:03:39+00:00

I’m trying to display text that is input by the user if it is

  • 0

I’m trying to display text that is input by the user if it is not null but I’m having some trouble (I’m a Java noob). Here is the flow of my app:

Starts at Main.java with a button:

-Button: Profile

If you click profile, the app goes to the profile page Display.java that also has a button:

-Button: Edit Profile

-This view also displays the information (name, phone number, zip code, etc)

When a user clicks Edit Profile, the program goes to a form at EditProfile.java, which has a form where users enter the information and then there is a button to submit.

-Button: Submit

This submit button takes the user back to the previous view (Display.java) and displays the information that was previously entered in the form with the string resultText.

I’m not sure how to make this work. If anyone has any suggestions, I’d really appreciate the help!

Edit: One thing to note is that I’m getting a “Dead Code” error on the if expression in Display.java

Display.java:

public class Display extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.display);

    String newline = System.getProperty("line.separator");

    TextView resultText = (TextView) findViewById(R.id.resultText);
    Bundle bundle = getIntent().getExtras();

    String firstName = null;
    String lastName;
    String phoneNumber;
    String city;
    String zipCode;

    if(firstName != null) {

        firstName = bundle.getString("EditTextFirstName");
        lastName = bundle.getString("EditTextLastName");
        phoneNumber = bundle.getString("EditTextPhoneNumber");
        city = bundle.getString("EditTextCity");
        zipCode = bundle.getString("EditTextZipCode");
        resultText.setText("Name: " + firstName + " " + lastName + newline + "Phone Number: " + phoneNumber +
        newline + "City: " + city + newline + "Zip Code: " + zipCode + newline);
    }

    Button profile = (Button) findViewById(R.id.button1);
    profile.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            startActivity(new Intent(Display.this, EditProfile.class));             
        }
    });
}   
}

EditProfile.java:

public class EditProfile extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.profile);       

 }
public void sendFeedback(View button) {
    final EditText firstnameField = (EditText)this.findViewById(R.id.EditTextFirstName);
    String firstname = firstnameField.getText().toString();

    final EditText lastnameField = (EditText) findViewById(R.id.EditTextLastName);
    String lastname = lastnameField.getText().toString();

    final EditText phoneNumberField = (EditText) findViewById(R.id.EditTextPhoneNumber);
    String phoneNumber = phoneNumberField.getText().toString();

    final EditText cityField = (EditText) findViewById(R.id.EditTextCity);
    String city = cityField.getText().toString();

    final EditText zipCodeField = (EditText) findViewById(R.id.EditTextZipCode);
    String zipcode = zipCodeField.getText().toString();

    int count = 0;
    int fnlen=firstname.length();
    int lnlen=lastname.length();
    int phlen=phoneNumber.length();
    int citylen=city.length();
    int zclen=zipcode.length();

    if (fnlen<=0){
        firstnameField.setError("Enter your first name");
    }
    else {
        count += 1;
    }



    if (lnlen<=0){
        lastnameField.setError("Enter your last name");
    }
    else {
        count += 1;
    }


    if (phlen<=0){
        phoneNumberField.setError("Enter your ten digit phone number");
    }
    else if (phlen!=10){
        phoneNumberField.setError("Phone number must be ten digits");
    }   
    else {
        count += 1;
    }

    if (citylen<=0){
        cityField.setError("Enter your city");
    }
    else {
        count += 1;         
    }
    if (zclen<=0){
        zipCodeField.setError("Enter your Zip Code");
    }
    else if (zclen!=5){
        zipCodeField.setError("Enter a five digit zip code");
    }
    else {
        count += 1;
    }   

    if (count == 5) {

        Intent intent = new Intent();
        intent.setClass(this,Display.class);
        intent.putExtra("EditTextFirstName",firstnameField.getText().toString());
        intent.putExtra("EditTextLastName",lastnameField.getText().toString());
        intent.putExtra("EditTextPhoneNumber",phoneNumberField.getText().toString());
        intent.putExtra("EditTextCity",cityField.getText().toString());
        intent.putExtra("EditTextZipCode",zipCodeField.getText().toString());

        startActivity(intent);
    }
    else {
        count = 0;
    }
}   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:03:40+00:00Added an answer on May 29, 2026 at 8:03 am

    try with `Intent i= getIntent();
    if(i.getExtras()!=null){

            firstName = bundle.getString("EditTextFirstName");
        lastName = bundle.getString("EditTextLastName");
        phoneNumber = bundle.getString("EditTextPhoneNumber");
        city = bundle.getString("EditTextCity");
        zipCode = bundle.getString("EditTextZipCode");
        resultText.setText("Name: " + firstName + " " + lastName + newline + "Phone Number: " + phoneNumber +
        newline + "City: " + city + newline + "Zip Code: " + zipCode + newline);
        }`in your Display Class instead of firstName != null) { ...} and let me know if any queries.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I need to clean up various Word 'smart' characters in user input, including but
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.