I am following an android tutorial it tells me to add this code to the main.xml file
<TextView
android:layout_width="fill_parent"
android:layout_height=height="wrap_content"
android:text="This is my first Android Application"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="And this is a clickable button!/>
the main.xml file contains this text, but when I add the above code to the bottom of the code below, it says "your code contains errors, please correct them and try again" What should I do?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
This is wrong:
<TextView
android:layout_width="fill_parent"
android:layout_height=height="wrap_content"
Change to:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
There are many errors in that code.
First TextView, remove the duplicated "=height" in layout_height:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is my first Android Application"/>
On your button, you're not closing the quotes in android:text. See:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="And this is a clickable button!"/>
Finally, put all that before the closing tag of LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- put stuff here -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<!-- or here -->
</LinearLayout>
You are missing a quotation mark:
android:text="And this is a clickable button!/>
fix:
android:text="And this is a clickable button!"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.