gpt4 book ai didi

java - Android Studio : Error parsing XML, 无法构建应用程序

转载 作者:行者123 更新时间:2023-12-02 03:25:56 25 4
gpt4 key购买 nike

当我尝试构建我的应用程序时,它给了我以下错误。

错误:(21) 解析 XML 时出错:格式不正确( token 无效)错误:任务“:app:processDebugResources”执行失败。

com.android.ide.common.process.ProcessException: Failed to execute aapt

这是我的 XML 代码,也是唯一的 XML 代码,请帮助我。

package com.example.madhur.calculator;

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

public class InnerWorkings extends Activity implements View.OnClickListener {

TextView tvvresults;
Button bvBackSpace, bvClear, bvPlusMinus, bvRoot, bvDivision, bvMultiply, bvSubtract, bvDot, bvEqual, bvAddition;
Button bv0, bv1, bv2, bv3, bv4, bv5, bv6, bv7, bv8, bv9;
int iResults, container, arithmaticCode, finalCalculation, remainder;

protected void onCreate(Bundle calculations) {
super.onCreate(calculations);

Initialization();
}

private void Initialization() {

tvvresults = (TextView) findViewById(R.id.tvResults);

bvBackSpace = (Button) findViewById(R.id.bBackSpace);
bvClear = (Button) findViewById(R.id.bClear);
bvPlusMinus = (Button) findViewById(R.id.bPlusMinus);
bvRoot = (Button) findViewById(R.id.bRoot);
bvDivision = (Button) findViewById(R.id.bDivision);
bvMultiply = (Button) findViewById(R.id.bMultiply);
bvSubtract = (Button) findViewById(R.id.bSubtract);
bvDot = (Button) findViewById(R.id.bDot);
bvEqual = (Button) findViewById(R.id.bEqual);
bvAddition = (Button) findViewById(R.id.bAddition);
bv0 = (Button) findViewById(R.id.b0);
bv1 = (Button) findViewById(R.id.b1);
bv2 = (Button) findViewById(R.id.b2);
bv3 = (Button) findViewById(R.id.b3);
bv4 = (Button) findViewById(R.id.b4);
bv5 = (Button) findViewById(R.id.b5);
bv6 = (Button) findViewById(R.id.b6);
bv7 = (Button) findViewById(R.id.b7);
bv8 = (Button) findViewById(R.id.b8);
bv9 = (Button) findViewById(R.id.b9);

bvBackSpace.setOnClickListener(this);
bvClear.setOnClickListener(this);
bvPlusMinus.setOnClickListener(this);
bvRoot.setOnClickListener(this);
bvDivision.setOnClickListener(this);
bvMultiply.setOnClickListener(this);
bvSubtract.setOnClickListener(this);
bvDot.setOnClickListener(this);
bvEqual.setOnClickListener(this);
bvAddition.setOnClickListener(this);
bv0.setOnClickListener(this);
bv1.setOnClickListener(this);
bv2.setOnClickListener(this);
bv3.setOnClickListener(this);
bv4.setOnClickListener(this);
bv5.setOnClickListener(this);
bv6.setOnClickListener(this);
bv7.setOnClickListener(this);
bv8.setOnClickListener(this);
bv9.setOnClickListener(this);
}

public void onClick(View v) {
switch (v.getId()) {
case R.id.bBackSpace:
remainder = iResults % 10;
iResults = iResults - remainder;
tvvresults.setText(iResults);
break;
case R.id.bClear:
iResults = 0;
tvvresults.setText(iResults);
break;
case R.id.bPlusMinus:
iResults = iResults * (-1);
tvvresults.setText(iResults);
break;
case R.id.bRoot:

break;
case R.id.bDivision:
arithmaticCode = 1;
container = iResults;
iResults = 0;
break;
case R.id.bMultiply:
arithmaticCode = 2;
container = iResults;
iResults = 0;
break;
case R.id.bSubtract:
arithmaticCode = 3;
container = iResults;
iResults = 0;
break;
case R.id.bDot:

break;
case R.id.bEqual:
Calculations();
break;
case R.id.bAddition:
arithmaticCode = 4;
container = iResults;
iResults = 0;
break;
case R.id.b0:
iResults = (iResults * 10);
tvvresults.setText(iResults);
break;
case R.id.b1:
iResults = (iResults * 10) + 1;
tvvresults.setText(iResults);
break;
case R.id.b2:
iResults = (iResults * 10) + 2;
tvvresults.setText(iResults);
break;
case R.id.b3:
iResults = (iResults * 10) + 3;
tvvresults.setText(iResults);
break;
case R.id.b4:
iResults = (iResults * 10) + 4;
tvvresults.setText(iResults);
break;
case R.id.b5:
iResults = (iResults * 10) + 5;
tvvresults.setText(iResults);
break;
case R.id.b6:
iResults = (iResults * 10) + 6;
tvvresults.setText(iResults);
break;
case R.id.b7:
iResults = (iResults * 10) + 7;
tvvresults.setText(iResults);
break;
case R.id.b8:
iResults = (iResults * 10) + 8;
tvvresults.setText(iResults);
break;
case R.id.b9:
iResults = (iResults * 10) + 9;
tvvresults.setText(iResults);
break;
}
}

private void Calculations() {
if (arithmaticCode == 1) {
finalCalculation = container / iResults;
tvvresults.setText(finalCalculation);
}
if (arithmaticCode == 2) {
finalCalculation = container * iResults;
tvvresults.setText(finalCalculation);
}
if (arithmaticCode == 3){
finalCalculation = container - iResults;
tvvresults.setText(finalCalculation);
}
if (arithmaticCode == 4){
finalCalculation = container + iResults;
tvvresults.setText(finalCalculation);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:gravity="center"
android:textSize="20dp"
android:text="0"
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="@+id/tvResults" />

<Button
android:text="<---"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bBackSpace"
android:layout_marginTop="21dp"
android:layout_below="@id/tvResults"
android:layout_alignParentStart="true"
android:layout_marginStart="21dp"/>

<Button
android:text="C"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bClear"
android:layout_below="@id/tvResults"
android:layout_toEndOf="@id/bBackSpace"
android:layout_marginStart="20dp"
android:layout_marginTop="21dp"/>

<Button
android:text="+/-"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bPlusMinus"
android:layout_below="@id/tvResults"
android:layout_toStartOf="@id/bRoot"
android:layout_marginEnd="20dp"
android:layout_marginTop="21dp" />

<Button
android:text="-v"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bRoot"
android:layout_marginEnd="21dp"
android:layout_marginTop="21dp"
android:layout_below="@id/tvResults"
android:layout_alignParentEnd="true" />

<Button
android:text="7"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b7"
android:layout_below="@id/bBackSpace"
android:layout_alignParentStart="true"
android:layout_marginStart="21dp"
android:layout_marginTop="20dp"/>

<Button
android:text="8"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b8"
android:layout_below="@id/bBackSpace"
android:layout_toEndOf="@id/bBackSpace"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />

<Button
android:text="9"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b9"
android:layout_below="@id/bBackSpace"
android:layout_toStartOf="@id/bDivision"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp" />

<Button
android:text="/"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bDivision"
android:layout_marginEnd="21dp"
android:layout_below="@id/bBackSpace"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"/>

<Button
android:text="4"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b4"
android:layout_below="@id/b7"
android:layout_alignParentStart="true"
android:layout_marginStart="21dp"
android:layout_marginTop="20dp"/>

<Button
android:text="5"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b5"
android:layout_below="@id/b8"
android:layout_toEndOf="@id/b4"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />

<Button
android:text="6"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b6"
android:layout_below="@id/b9"
android:layout_toStartOf="@id/bMultiply"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp" />

<Button
android:text="*"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bMultiply"
android:layout_marginEnd="21dp"
android:layout_below="@id/bDivision"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"/>

<Button
android:text="1"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b1"
android:layout_below="@id/b4"
android:layout_alignParentStart="true"
android:layout_marginStart="21dp"
android:layout_marginTop="20dp"/>

<Button
android:text="2"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b2"
android:layout_below="@id/b5"
android:layout_toEndOf="@id/b4"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />

<Button
android:text="3"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b3"
android:layout_below="@id/b6"
android:layout_toStartOf="@id/bSubtract"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp" />

<Button
android:text="-"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bSubtract"
android:layout_marginEnd="21dp"
android:layout_below="@id/bMultiply"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"/>

<Button
android:text="0"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/b0"
android:layout_below="@id/b1"
android:layout_alignParentStart="true"
android:layout_marginStart="21dp"
android:layout_marginTop="20dp"/>

<Button
android:text="="
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bEqual"
android:layout_below="@id/b3"
android:layout_toStartOf="@id/bAddition"
android:layout_marginEnd="20dp"
android:layout_marginTop="20dp" />

<Button
android:text="+"
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bAddition"
android:layout_marginEnd="21dp"
android:layout_below="@id/bSubtract"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"/>

<Button
android:text="."
android:textStyle="bold"
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/bDot"
android:layout_below="@id/b2"
android:layout_toEndOf="@id/b1"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"/>

</RelativeLayout>
</LinearLayout>

最佳答案

尝试替换android:text="<---"通过android:text="&lt;---" ,第 21 行。

关于java - Android Studio : Error parsing XML, 无法构建应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38895688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com