当前位置: 首页 > 知识库问答 >
问题:

Android.View.InflateException:二进制XML文件行#54:inflating类EditText时出错

堵景天
2023-03-14

“Android.View.InflateException:二进制XML文件行#54:Error inflating class EditText”是在由于项目而完成登录屏幕并运行时生成的。我怎么解决这个?

package com.example.min.project;

import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

public class LoginActivity extends AppCompatActivity {

    private AlertDialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);


        final EditText idText = (EditText) findViewById(R.id.idText);
        final EditText passwordText = (EditText)findViewById(R.id.passwordText);
        final Button loginButton = (Button) findViewById(R.id.loginButton);

        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String id = idText.getText().toString();
                String pw = passwordText.getText().toString();

                Response.Listener<String> responseLister = new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try
                        {
                            JSONObject jsonResponse = new JSONObject(response);
                            boolean success = jsonResponse.getBoolean("success");
                            if(success){
                                AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                                dialog = builder.setMessage("success login")
                                        .setPositiveButton("확인", null)
                                        .create();
                                dialog.show();
                                Intent intent = new Intent(LoginActivity.this, NoticeActivity.class);
                                LoginActivity.this.startActivity(intent);
                                finish();
                            }
                            else{
                                AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                                dialog = builder.setMessage("Please check your ID and password.")
                                        .setNegativeButton("Retry", null)
                                        .create();
                                dialog.show();
                            }

                        }
                        catch (Exception e)
                        {
                            e.printStackTrace();
                        }
                    }
                };
                LoginRequest loginRequest = new LoginRequest(id, pw, responseLister);
                RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
                queue.add(loginRequest);
            }
        });

    }
    protected void onStop(){
        super.onStop();
        if(dialog != null)
        {
            dialog.dismiss();
            dialog = null;
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="51dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="227dp"
            android:background="@color/colorLogin"
            android:orientation="vertical">

            <ImageView
                android:layout_width="125dp"
                android:layout_height="125dp"
                android:layout_gravity="center"
                android:layout_marginTop="20dp"
                android:src="@drawable/sunmoon" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="scholl"
                android:textColor="#000000"
                android:textSize="25dp"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="attend system"
                android:textColor="#000000"
                android:textSize="18dp"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <EditText
                android:id="@+id/idText"
                android:layout_width="230dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="50dp"
                android:background="@drawable/round_background"
                android:drawableLeft="@drawable/ic_person_black_24dp"
                android:hint="Id"
                android:padding="10dp"
                android:textColor="#808080"
                android:textColorHint="#808080" />

            <EditText
                android:id="@+id/passwordText"
                android:layout_width="230dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:background="@drawable/round_background"
                android:drawableLeft="@drawable/ic_lock_black_24dp"
                android:hint="Pw"
                android:inputType="textPassword"
                android:padding="10dp"
                android:textColor="#808080"
                android:textColorHint="#808080" />

            <Button
                android:id="@+id/loginButton"
                android:layout_width="280dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:background="@color/colorPrimaryDark"
                android:text="login"
                android:textColor="#ffffff"
                android:textSize="20dp"
                android:textStyle="bold" />
        </LinearLayout>


    </LinearLayout>

</android.support.constraint.ConstraintLayout>

共有1个答案

华俊贤
2023-03-14

您有如下round_background.xml所示的背景。通过Ctrl+shift+N查找并键入此xml名称。

将其移至res>drawable

 类似资料: