android.view.InflateException:二进制XML文件行#31:错误类膨胀

时间:2016-06-05 12:58:07

标签: android xml android-studio

这给我一个错误,我不明白为什么这给我这个错误,我的图标大小是300kb。

main_menu.xml

package com.example.jaypeetan.mftis;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class main_menu extends AppCompatActivity {
    Context context;
    static String a_username;
    static String a_password;
    boolean arduino = true;
    private String m_pass = "";

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

        ImageView abtn_logout = (ImageView) findViewById(R.id.btn_logout);

        abtn_logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(main_menu.this,login.class);
                startActivity(i);
            }
        });
    }
    public void onPreferences(View view){
        Intent intent = new Intent(main_menu.this,preferences.class);
        startActivity(intent);
    }
    public void onExit(View view){
        System.exit(1);
    }
    //UNLOCK THE DEVICE
    public void onLock(View view){
        final ImageView access_view = (ImageView) findViewById(R.id.image_access);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Enter the Password");
        // Set up the input
        final EditText input = new EditText(this);
        // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
        input.setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD);
        builder.setView(input);
        // Set up the buttons
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int pass) {
                m_pass = input.getText().toString();
                if(arduino==true){
                    if(m_pass.equals(a_password)){
                        Toast.makeText(getApplicationContext(),"The Drawer is now Locked",Toast.LENGTH_SHORT).show();
                        arduino = false;
                    }
                    else{
                        Toast.makeText(getApplicationContext(),"Wrong Password Please try again",Toast.LENGTH_SHORT).show();
                    }
                }else{
                    if(m_pass.equals(a_password)){
                        Toast.makeText(getApplicationContext(),"The Drawer is now UnLocked",Toast.LENGTH_SHORT).show();
                        arduino = true;
                    }
                    else{
                        Toast.makeText(getApplicationContext(),"Wrong Password Please try again",Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();
    }
}

main_menu.java

06-05 20:57:38.875 22631-22631/com.example.jaypeetan.mftis E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.example.jaypeetan.mftis, PID: 22631
                                                                         java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jaypeetan.mftis/com.example.jaypeetan.mftis.main_menu}: android.view.InflateException: Binary XML file line #31: Error inflating class <unknown>
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:139)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:149)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5257)
                                                                             at java.lang.reflect.Method.invokeNative(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:515)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
                                                                             at dalvik.system.NativeStart.main(Native Method)
                                                                          Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class <unknown>
                                                                             at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                             at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                                                                             at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
                                                                             at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                             at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
                                                                             at com.example.jaypeetan.mftis.main_menu.onCreate(main_menu.java:29)
                                                                             at android.app.Activity.performCreate(Activity.java:5411)
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:139) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:149) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                                             at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                             at dalvik.system.NativeStart.main(Native Method) 
                                                                          Caused by: java.lang.reflect.InvocationTargetException
                                                                             at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                             at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                                                                             at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                                                                             at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                                                                             at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
                                                                             at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                             at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249) 
                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 
                                                                             at com.example.jaypeetan.mftis.main_menu.onCreate(main_menu.java:29) 
                                                                             at android.app.Activity.performCreate(Activity.java:5411) 
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270) 
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:139) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:149) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                                             at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                             at dalvik.system.NativeStart.main(Native Method) 
                                                                          Caused by: java.lang.OutOfMemoryError
                                                                             at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                                             at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
                                                                             at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
                                                                             at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
                                                                             at android.content.res.Resources.loadDrawable(Resources.java:2192)
                                                                             at android.content.res.Resources.loadDrawable(Resources.java:2075)
                                                                             at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                             at android.widget.ImageView.<init>(ImageView.java:129)
                                                                             at android.widget.ImageView.<init>(ImageView.java:119)
                                                                             at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                             at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                                             at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                                             at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                                                                             at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
                                                                             at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                             at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249) 
                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 
                                                                             at com.example.jaypeetan.mftis.main_menu.onCreate(main_menu.java:29) 
                                                                             at android.app.Activity.performCreate(Activity.java:5411) 
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270) 
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:139) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:149) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                                             at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                             at dalvik.system.NativeStart.main(Native Method) 

这是错误

<h:outputText styleClass="postprocessedtick" rendered="#{filteredDump.postProcessed == 'YES'}" />

我认为问题出在我的ImageView with iD:image_access上 我不明白为什么它给我这个错误 感谢您的帮助:)

2 个答案:

答案 0 :(得分:2)

如果您的徽标图标是向量更改您的ImageView

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    app:srcCompat="@drawable/logo"
    tools:ignore="MissingPrefix"
    android:layout_above="@+id/button_login" />

答案 1 :(得分:1)

您的图标图片文件太大,需要将其调整到合理的大小。即56x56或最大512x512

使用图像软件或在线调整图片大小调整网页应用程序来调整图标大小。

您还可以使用TinyPNG进一步压缩图标图像。

遵循Google {/ 3>}的official documentation设计指南

Reference Link