Home Articles

android.view.InflateException:二进制XML文件行#54:错误输出类EditText

Asked
Viewed 1320 times
0

'android.view.InflateException:二进制XML文件行#54:当登录屏幕由于项目而完成并运行时,会生成错误膨胀类EditText' . 我该如何解决这个问题?

以下是错误内容和来源 .

错误:E / AndroidRuntime:FATAL EXCEPTION:main进程:com.example.min.project,PID:2930 java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.min.project / com.example.min . project.LoginActivity}:android.view.InflateException:二进制XML文件行#54:android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:)在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)上的类EditText错误 . 2387)在Android.app.Handler.dispatchMessage(Handler.java:102)的android.app.ActivityThread.access $ 800(ActivityThread.java:151)android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)在android.os.Looper.loop(Looper.java:135)的android.app.ActivityThread.main(ActivityThread.java:5254),位于java.lang.reflect的java.lang.reflect.Method.invoke(Native Method) .Method.invoke(Method.java:372)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)at com.android.internal.os.ZygoteInit.main(Zygote) Init.java:698)引起:android.view.InflateException:二进制XML文件行#54:在android.view.LayoutInflater.rInflate(在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)处输出类EditText时出错( LayoutInflater.java:806)android.view.LayoutInflater.rInflate(LayoutInflater.java:809)android.view.LayoutInflater.rInflate(LayoutInflater.java:809)android.view.LayoutInflater.inflate(LayoutInflater.java:504) )android.view.LayoutInflater.inflate(LayoutInflater.java:414)android.view.LayoutInflater.inflate(LayoutInflater.java:365)android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)在Android.app.Activity.performCreate(Activity.java)的com.example.min.project.LoginActivity.onCreate(LoginActivity.java:24)上的android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) :5990)在android.app.ActivityThread的android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) .performLaunchActivity(ActivityThread.java:2278)在android.app.ActivityThread.access $ 800(ActivityThread.java:151)的android.app.ActivityThread $ H.handleMessage上的android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) (ActivityThread.java:1303)android.app.Handler.dispatchMessage(Handler.java:102)位于android.app.ActivityThread.main的android.os.Looper.loop(Looper.java:135)处(ActivityThread.java: 5254)at java.lang.reflect.Method.invoke(Native Method)at java.lang.reflect.Method.invoke(Method.java:372)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit . java:903)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)引起:android.content.res.Resources $ NotFoundException:资源“com.example.min.project:drawable / round_background” (7f060068)不是Drawable(颜色或路径):在Android的android.content.res.Resources.loadDrawableForCookie(Resources.java:2441)上的TypedValue {t = 0x1 / d = 0x7f060068 a = -1 r = 0x7f060068} . content.res.Resources.lo adDrawable(Resources.java:2381)位于Android.widget.TextView的android.view.View . (View.java:3737)的android.content.res.TypedArray.getDrawable(TypedArray.java:749) . (TextView.java :637)在android.widget.EditText . (EditText.java:65)android.widget.EditText . (EditText.java:61)android.support.v7.widget.AppCompatEditText . (AppCompatEditText.java:64)at在android.support.v7.app.AppCompatViewInflater.createEditText(AppCompatViewInflater.java:191)的android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater)中的android.support.v7.widget.AppCompatEditText . (AppCompatEditText.java:60) .java:113)位于android.sview.LayoutInflater的android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1035)android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092) . android.view.LayoutInflater.rInflate(LayoutInflater)中的android.view.LayoutInflater.rInflate(LayoutInflater.java:806)中的createViewFromTag(LayoutInflater.java:725) . java:809)在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)的android.view.LayoutInflater.inflate(LayoutInflater.java:504)at atandroid.view.LayoutInflater.inflate(LayoutInflater.java:414)android.view.LayoutInflater.inflate(LayoutInflater.java:365)android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)at android .support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)位于android.app.Activity.performCreate(Activity.java:5990)的com.example.min.project.LoginActivity.onCreate(LoginActivity.java:24) )在android.app.Anstrumentation.callActivityOnCreate(Instrumentation.java:1106)android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)android.app .ActivityThread.access $ 800(ActivityThread.java:151)在Android.os.Looper的android.app.Handler.dispatchMessage(Handler.java:102)的android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303) .loop(Looper.java:135)在java.lang.reflect.Metho的android.app.ActivityThread.main(ActivityThread.java:5254) d.invoke(Native Method)位于com.android的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)的java.lang.reflect.Method.invoke(Method.java:372) . internal.os.ZygoteInit.main(ZygoteInit.java:698)

LoginActivity源:

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;
        }
    }
}

Login.xml:

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

  • 0

    你有一个像 round_background.xml 的背景 . 按 ctrl + shift + n 查找并输入此xml名称 .

    将其移至 res>drawable .

Related