1

I am new to android programming and recently installed Eclipse junos and ADT plugin on my ubuntu system and downloaded the android SDK. After this, i created an android project, which by default is the hello world program, when i run this program i got an error "Error in an XML file: aborting build.". But i haven't edited any code. Please help me solve this problem. Below is the program. I get an error also saying R cannot be resolved to a variable.

package com.example.myandroid;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

public class MainActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Here is the activity_main.xml

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
    <TextView android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" 
            android:layout_centerVertical="true" 
            android:text="@string/hello_world" 
            tools:context=".MainActivity" /> 
</RelativeLayout>
18
  • Send your XML file activity_main. Commented Oct 23, 2012 at 6:54
  • <RelativeLayout xmlns:android="schemas.android.com/apk/res/android" xmlns:tools="schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" tools:context=".MainActivity" /> </RelativeLayout> Commented Oct 23, 2012 at 6:58
  • Could you post it in the question (edit the question)? THat would make it a bit more readable :) Commented Oct 23, 2012 at 6:59
  • 2
    edit (add one extra space in last or first line) MainActivity.java and execute again. Commented Oct 23, 2012 at 7:01
  • To get rid of the "R cannot be resolved to a variable" error try using "import com.example.myandroid.R" Commented Oct 23, 2012 at 7:31

2 Answers 2

1
<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"; xmlns:tools="schemas.android.com/tools"; 

the semicolon above seems to be the problem try and remove them

Sign up to request clarification or add additional context in comments.

2 Comments

No, that did not help either.
link My problem is exactly like this. Please help.
0

Try this

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >
        <TextView android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true" 
                android:layout_centerVertical="true" 
                android:text="@string/hello_world" 
                tools:context=".MainActivity" /> 
    </RelativeLayout>

You have extra semi colons in your xml file.

Also make sure the first line of your xml is

<?xml version="1.0" encoding="utf-8"?>

So your complete xml should look like

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
    <TextView android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:text="@string/hello_world" 
        tools:context=".MainActivity" /> 
</RelativeLayout>

12 Comments

Are you using Eclipse for developement?
There seems to be nothing wrong with your java file, however your updated xml still has the extra semi colons (;) you need to remove those.
Yes, I am using Eclipse Juno in ubuntu with Open JDK java.
You might want to clear your xml and try and use the code that I have provided. See if that helps.
I have updated my XML file now. I also used your code. But still get the same error. Is there any other problem.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.