• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

main.xml problem

mada_2013

Lurker
Hello,

I am new to Android and have just started trying to build the calculator tutorial at the link below from the Android website:

http://cloud101.eu/blog/2012/03/10/android-introduction-to-a-simple-calculator/

When I have the xml code setup in the layout/main.xml file as in the tutorial, I get two errors and I'm not sure why. The errors are

Error parsing XML: junk after document element main.xml /Calculator_Android/res/menu line 11 Android AAPT Problem

and

The processing instruction target matching "[xX][mM][lL]" is not allowed. main.xml /Calculator_Android/res/menu line 11 Android XML Format Problem


I have included the code below and would be very grateful if someone could explain the problem with the code.



<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>

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

<LinearLayout
android:id="@+id/linearLayoutH1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="vertical"
android:weightSum="1" >
<EditText
android:id="@+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_weight=".50"
/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_weight=".50"
/>
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayoutH3"
android:layout_width="fill_parent"
android:layout_height="100dp"

android:orientation="horizontal"
android:weightSum="1.0" >

<Button
android:id="@+id/buttonClear"
style="@style/ButtonText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:background="@drawable/custombuttonred"
android:text="@string/clear"
android:layout_weight=".43"
android:textSize="40sp" />

<ImageButton
style="@style/ButtonText"
android:id="@+id/c101_image"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:scaleType="centerInside"
android:background="@drawable/cloud101"
android:layout_weight=".14" />


<Button
android:id="@+id/buttonBackspace"
style="@style/ButtonText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:background="@drawable/custombuttonred"
android:text="@string/backspace"
android:layout_weight=".43"
android:textSize="30sp" />

</LinearLayout>

<LinearLayout
android:id="@+id/linearLayoutH2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >

<Button
android:id="@+id/button1"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="@string/b1"
android:textSize="40sp" />

<Button
android:id="@+id/button2"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="2"
android:textSize="40sp" />

<Button
android:id="@+id/button3"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="3"
android:textSize="40sp" />

<Button
android:id="@+id/buttonDevide"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="/"
android:textSize="40sp" />
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayoutH3"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >

<Button
android:id="@+id/button4"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="4"
android:textSize="40sp" />

<Button
android:id="@+id/button5"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="5"
android:textSize="40sp" />

<Button
android:id="@+id/button6"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="6"
android:textSize="40sp" />

<Button
android:id="@+id/buttonMult"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="X"
android:textSize="40sp" />
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayoutH4"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >

<Button
android:id="@+id/button7"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="7"
android:textSize="40sp" />

<Button
android:id="@+id/button8"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="8"
android:textSize="40sp" />

<Button
android:id="@+id/button9"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="9"
android:textSize="40sp" />

<Button
android:id="@+id/buttonMinus"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="-"
android:textSize="40sp" />
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayoutH5"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >

<Button
android:id="@+id/button0"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="0"
android:textSize="40sp" />

<Button
android:id="@+id/buttonDot"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="."
android:textSize="40sp" />

<Button
android:id="@+id/buttonEq"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttongreen"
android:text="="
android:textSize="40sp" />

<Button
android:id="@+id/buttonPlus"
style="@style/ButtonText"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="+"
android:textSize="40sp" />
</LinearLayout>
 
<?xml version="1.0" encoding="utf-8"?> should be the first line.

Also, I think what you have should be in two files? Everything above this line in /res/menu/main.xml and the rest in /res/layout/main.xml.
 
Back
Top Bottom