Saumya
Saumya

Reputation: 83

Error:(21) Error parsing XML: not well-formed (invalid token)

The r class is not resolved. I tried clean then rebuild but i failed because of the following errors

Error:(21) Error parsing XML: not well-formed (invalid token)
Error:Execution failed for task ':app:processDebugResources'. 
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Saumya\AppData\Local\Android\Sdk\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1

I tried to find an error in my xml but couldn't.

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MyActivity">

    <TextView
        android:id="@+id/T1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="70dp"
        android:hint="Result" />

    < EditText
        android:id="@+id/E1"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:inputType="number|numberDecimal|numberSigned" />


    < EditText
        android:id="@+id/E2"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="130dp"
        android:inputType="number|numberDecimal|numberSigned" />

    < EditText
        android:id="@+id/E3"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="230dp"
        android:inputType="number|numberDecimal|numberSigned" />


    <Button
        android:id="@+id/clr"
        android:layout_width="80dp"
        android:layout_height="45dp"
        android:layout_marginTop="120dp"
        android:onClick="res"
        android:text="C" />

    <Button
        android:id="@+id/div"
        android:layout_width="100dp"
        android:layout_height="45dp"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="120dp"
        android:onClick="res"
        android:text="/" />

    <Button
        android:id="@+id/mul"
        android:layout_width="100dp"
        android:layout_height="45dp"
        android:layout_marginLeft="220dp"
        android:layout_marginTop="120dp"
        android:onClick="res"
        android:text="*" />

    <Button
        android:id="@+id/B7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="200dp"
        android:text="7" />

    <Button
        android:id="@+id/B8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="200dp"
        android:text="8" />

    <Button
        android:id="@+id/B9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="200dp"
        android:layout_marginTop="200dp"
        android:text="9" />


    <Button
        android:id="@+id/sub"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="300dp"
        android:layout_marginTop="200dp"
        android:onClick="res"
        android:text="-" />

    <Button
        android:id="@+id/B4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="280dp"
        android:text="4" />

    <Button
        android:id="@+id/B5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="280dp"
        android:text="5" />

    <Button
        android:id="@+id/add"
        android:layout_width="wrap_content"
        android:layout_height="120dp"
        android:layout_marginLeft="300dp"
        android:layout_marginTop="280dp"
        android:onClick="res"
        android:text="+" />

    <Button
        android:id="@+id/B6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="200dp"
        android:layout_marginTop="280dp"
        android:text="6" />

    <Button
        android:id="@+id/B1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="360dp"
        android:text="1" />

    <Button
        android:id="@+id/B2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="360dp"
        android:text="2" />

    <Button
        android:id="@+id/B3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="200dp"
        android:layout_marginTop="360dp"
        android:text="3" />

    <Button
        android:id="@+id/B0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="440dp"
        android:text="0" />

    <Button
        android:id="@+id/dec"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="440dp"
        android:text="." />

    <Button
        android:id="@+id/calc"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="200dp"
        android:layout_marginTop="440dp"
        android:onClick="res"
        android:text="=" />


</RelativeLayout>

JAVA file

package com.example.android.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class MyActivity extends Activity {

    EditText e1, e2, e3;
    TextView t1;
    Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ADD, SUB, MUL, DIV, CLR, CALC, DEC;
    String a, b, opr;
    float result;

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

        e1 = (EditText) findViewById(R.id.E1);
        t1 = (TextView) findViewById(R.id.T1);
        b0 = (Button) findViewById(R.id.B0);
        b1 = (Button) findViewById(R.id.B1);
        b2 = (Button) findViewById(R.id.B2);
        b3 = (Button) findViewById(R.id.B3);
        b4 = (Button) findViewById(R.id.B4);
        b5 = (Button) findViewById(R.id.B5);
        b6 = (Button) findViewById(R.id.B6);
        b7 = (Button) findViewById(R.id.B7);
        b8 = (Button) findViewById(R.id.B8);
        b9 = (Button) findViewById(R.id.B9);
        b0 = (Button) findViewById(R.id.B0);
        ADD = (Button) findViewById(R.id.add);
        SUB = (Button) findViewById(R.id.sub);
        MUL = (Button) findViewById(R.id.mul);
        DIV = (Button) findViewById(R.id.div);
        CLR = (Button) findViewById(R.id.clr);
        CALC = (Button) findViewById(R.id.calc);
        DEC = (Button) findViewById(R.id.dec);

    }

    public void res(View v) {
        a = e1.getText().toString();
        Float i = Float.valueOf(a);
        b = e3.getText().toString();
        Float j = Float.valueOf(b);
        opr = e2.getText().toString();
        Float k = Float.valueOf(opr);

        switch (v.getId())

        {
            case R.id.add:
                result = i + j;
                break;
            case R.id.sub:
                result = i - j;
                break;
            case R.id.mul:
                result = i * j;
                break;
            case R.id.div:
                result = i / j;
                break;
            case R.id.clr:
                t1.setText(" ");
            case R.id.calc:
                t1.setText(Float.toString(result));
                break;
            default:
                System.out.println("ERROR");


        }
    }


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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Upvotes: 0

Views: 665

Answers (1)

Rohit5k2
Rohit5k2

Reputation: 18112

This error means there is a compilation error in your XML file.

Seem like extra space at < EditText is causing the issue.

Try removing the space at < EditText. You have three such EditText.

Upvotes: 1

Related Questions