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 8241973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:00:56+00:00 2026-06-07T21:00:56+00:00

Sorry to make another topic on this subjcet but I’ve already read several of

  • 0

Sorry to make another topic on this subjcet but I’ve already read several of them and still don’t know why I’m getting this error. I followed the “Building Your First App” tutorial on http://developer.android.com/training/basics/firstapp/index.html and then tried to modify my application to give a layout to DisplayMessageActivity Class. I’ve created a file called “activity_displaymessage.xml” and implemented it to the class.

I’m new to android and I’m trying to understand how this all works. What am I doing wrong?

Here is my code:

MainActivity.java

public class MainActivity extends Activity {

    public final static String EXTRA_MESSAGE = "com.example.sampleandroid.MESSAGE";

        .
        .
        .


    public void sendMessage(View view){
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText =  (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }
}

DisplayMessageActivity.java

public class DisplayMessageActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_displaymessage);

        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

        TextView textview = (TextView) findViewById(R.id.text_view);
        textview.setText(message);

        setContentView(textview);
    }
}

activity_displaymessage.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="2">

    <TextView android:id="@+id/text_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="30sp"/>

</LinearLayout>
  • 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-06-07T21:00:58+00:00Added an answer on June 7, 2026 at 9:00 pm

    You have two setContentView.Your layout file activity_displaymessage have already child view R.id.text_view then why are you set it as setContentView().

    setContentView(R.layout.activity_displaymessage); and setContentView(textview);

    Remove this line setContentView(textview);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, I know this question is easy, but I don't know how to get
Sorry to be editing this once again, but rather than make another post, I
I know that this is a popular topic, but I've yet to find an
I'm sorry to post another question on this, but I just seem to be
Sorry for this simple question, but I can't solve it... There is an example:
Sorry but I am not sure how to ask this question but I am
Sorry if this question seems stupid, but it's stumped me for a couple days,
I'm really sorry. This must seem like an incredibly stupid question, but unless I
sorry if you'll find this question stupid, but I really need help. Here's some
sorry if my question kind of doesn't make sense but i am total confused

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.