无法在某些设备中为EditText充气

时间:2016-10-03 09:31:17

标签: android android-edittext layout-inflater android-studio-2.2 android-x86

我的应用程序遇到了一些设备问题(即Asus Zenfone 5(基于Intel的处理器))。打开时它会被强制关闭。这是来自设备的日志:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.coolappz.FitPartners/com.coolappz.FitPartners.ui.MainActivity}: android.view.InflateException: Binary XML file line #42: Error inflating class com.coolappz.FitPartners.ui.custom.CustomFontEditText
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2320)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2380)
 at android.app.ActivityThread.access$800(ActivityThread.java:151)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:135)
 at android.app.ActivityThread.main(ActivityThread.java:5289)
 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:898)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: android.view.InflateException: Binary XML file line #42: Error inflating class com.coolappz.FitPartners.ui.custom.CustomFontEditText
 at android.view.LayoutInflater.createView(LayoutInflater.java:633)
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
 at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
 at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
 at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
 at com.coolappz.FitPartners.ui.MainActivity.onCreate(MainActivity.java:165)
 at android.app.Activity.performCreate(Activity.java:6018)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2273)
 ... 10 more
Caused by: java.lang.reflect.InvocationTargetException
 at java.lang.reflect.Constructor.newInstance(Native Method)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
 at android.view.LayoutInflater.createView(LayoutInflater.java:607)
 ... 22 more
Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 96
 at android.content.res.TypedArray.getColor(TypedArray.java:401)
 at android.widget.TextView.<init>(TextView.java:717)
 at android.widget.EditText.<init>(EditText.java:65)
 at android.widget.EditText.<init>(EditText.java:61)
 at android.widget.EditText.<init>(EditText.java:57)
 at com.coolappz.FitPartners.ui.custom.CustomFontEditText.<init>(CustomFontEditText.java:18)
 ... 25 more

问题是,这只是设备上的错误。我已经在模拟器(基于ARM和基于x86)和其他设备中尝试过应用程序,并且它工作正常。

有没有人有同样的问题?我使用android studio with gradle 2.2.0。

这是customFontEditText类,我忘了提及,当我将CustomFontEditText更改为普通的EditText时,它仍然被强制关闭

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.EditText;

/**
 * Created by harto on 4/22/2016.
 */
public class CustomFontEditText extends EditText {
    public CustomFontEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    public CustomFontEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomFontEditText(Context context) {
        super(context);
        init();
    }

    private void init() {
        if (!isInEditMode()) {
            Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/SourceSansPro-Regular.otf");
            setTypeface(tf);
        }
    }
}

我在第一次构建时使用gradle v2.1.0,并且在我第一次构建它时它被强制关闭

1 个答案:

答案 0 :(得分:0)

降级可能值得一试:

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0'
}