user2291950
user2291950

Reputation: 9

android beginner tutorial Error parsing XML

I have just started the beginner's tutorial on android and I get 4 errors when compiling, even tho the code is basically copied from the webpage and I have followed all the steps. The errors are as follows:

Here is the code: activity_main.xml

    <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" 

        <EditText android:id="@+id/edit_message"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="@string/edit_message"
            android:layout_weight="1" />

        <Button android:layout_width="wrap content"
            android:layout_height="wrap_content"
            android:text="@string/button_send" /> 

    </LinearLayout>

MainActivity.java

    package com.example.test;

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;

    public class MainActivity extends Activity {

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


        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

    }

I searched everywhere, tried everything and it still won't work, so this is my last hope. Thanks!

Upvotes: 0

Views: 834

Answers (2)

Parijat Bose
Parijat Bose

Reputation: 390

 <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" >
    <EditText android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message"
        android:layout_weight="1" />
    <Button android:layout_width="wrap content"
        android:layout_height="wrap_content"
        android:text="@string/button_send" /> 
</LinearLayout>

Copy this, clean project and run. You didn't ended the LinearLayout tag before EditText.

Upvotes: 0

Pragnani
Pragnani

Reputation: 20155

Your LinearLayout tag should be closed.

i.e

 <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" <-- close here

like this

 <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" >

Upvotes: 2

Related Questions