RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 602537
Accepted
Александр
Александр
Asked:2020-12-12 18:15:52 +0000 UTC2020-12-12 18:15:52 +0000 UTC 2020-12-12 18:15:52 +0000 UTC

xml 标记中的错误:解析 xml 时出错:格式不正确(无效标记)

  • 772

我写了一个简单的应用程序,它根据输入的值计算一个函数(所谓的分段函数)。

问题是,在设备上编译和运行时(运行 android 4.4 的平板电脑,该项目也分别为 android 4.4 创建),出现描述的错误,并带有指向描述应用程序表单的 xml 的链接。我从头开始重写了应用程序,通过复制粘贴内容重新创建了项目,清理并重建,但无济于事。

附加代码: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:id="@+id/activity_main"
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="com.example.lab02a2andr_.MainActivity">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:weightSum="1">

    <TextView
        android:text="введите Х:"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView3"
        android:layout_weight="0.03" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="0.0"
        android:ems="10"
        android:id="@+id/editText" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RadioButton
            android:text="sin(x^2-3) x<=-1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/radioButton1" />

        <RadioButton
            android:text="(x+4)*x^2-3 -1<x<1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/radioButton3" />

        <RadioButton
            android:text="cos(sqrt(x)) x>=1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/radioButton2" />

    </RadioGroup>

    <CheckBox
        android:text="Удвоить"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/checkBox"
        android:layout_weight="0.03" />

    <Button
        android:text="Посчитать"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:layout_weight="0.03" />

    <TextView
        android:text="Ответ:"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.03"
        android:id="@+id/textView2" />
</LinearLayout>

主要活动:

package com.example.lab02a2andr_;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity {

private CheckBox cb;
private TextView tv2;
private RadioButton rb1,rb2,rb3;
private EditText et1;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    cb=(CheckBox) findViewById(R.id.checkBox);
    tv2=(TextView) findViewById(R.id.textView2);
    rb1=(RadioButton) findViewById(R.id.radioButton1);
    rb2=(RadioButton) findViewById(R.id.radioButton2);
    rb3=(RadioButton) findViewById(R.id.radioButton3);
    et1=(EditText) findViewById(R.id.editText);
    button = (Button) findViewById(R.id.button);
    et1.setOnFocusChangeListener(new View.OnFocusChangeListener(){
        public void onFocusChange(View v, boolean hasFocus){
            if(!hasFocus){
                Calculate();
            }
        }
    });
    rb1.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            Calculate();
        }
    });
    rb2.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            Calculate();
        }
    });
    rb3.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            Calculate();
        }
    });
    cb.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            Calculate();
        }
    });
    button.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            Calculate();
        }
    });
}

public void Calculate(){
    String s1;
    double x,y=0;
    int var;

    s1=et1.getText().toString();
    x=Double.parseDouble(s1);


    if(rb1.isChecked()==true){
        var=1;
    }else if(rb2.isChecked()==true){
        var=2;
    }else if(rb3.isChecked()==true){
        var=3;
    }else{
        if(x<=-1) {
            var = 1;
            rb1.setChecked(true);
        }else if(x>=1){
            var=3;
            rb3.setChecked(true);
        }else{
            var=2;
            rb2.setChecked(true);
        }
    }

    switch (var){
        case 1:
            y=Math.sin(x*x-3);
            break;
        case 2:
            y=(x+4)*x*x-3;
            break;
        case 3:
            y=Math.cos(Math.sqrt(x));
            break;
    }

    if(cb.isChecked()==true){
        y*=2;
    }

    s1="Ответ: "+Double.toString(y);

}
}
android
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    Tommy
    2020-12-12T18:44:18Z2020-12-12T18:44:18Z

    最有可能的是,符号会产生问题<并>尝试在文件中写入您的文本RadioButton,string并RadioButton指定指向的链接@string

    • 1
  2. user194625
    2020-12-12T18:24:40Z2020-12-12T18:24:40Z

    您忘记将此行添加到标记中的根标记

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

    这是命名空间android

    • 0

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    如何停止编写糟糕的代码?

    • 3 个回答
  • Marko Smith

    onCreateView 方法重构

    • 1 个回答
  • Marko Smith

    通用还是非通用

    • 2 个回答
  • Marko Smith

    如何访问 jQuery 中的列

    • 1 个回答
  • Marko Smith

    *.tga 文件的组重命名(3620 个)

    • 1 个回答
  • Marko Smith

    内存分配列表C#

    • 1 个回答
  • Marko Smith

    常规赛适度贪婪

    • 1 个回答
  • Marko Smith

    如何制作自己的自动完成/自动更正?

    • 1 个回答
  • Marko Smith

    选择斐波那契数列

    • 2 个回答
  • Marko Smith

    所有 API 版本中的通用权限代码

    • 2 个回答
  • Martin Hope
    jfs *(星号)和 ** 双星号在 Python 中是什么意思? 2020-11-23 05:07:40 +0000 UTC
  • Martin Hope
    hwak 哪个孩子调用了父母的静态方法?还是不可能完成的任务? 2020-11-18 16:30:55 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    Arch ArrayList 与 LinkedList 的区别? 2020-09-20 02:42:49 +0000 UTC
  • Martin Hope
    iluxa1810 哪个更正确使用:if () 或 try-catch? 2020-08-23 18:56:13 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5