0

我正在尝试使用 Saripaar 库在发送表单之前对其进行验证。但是我在 XML 中遇到了一些膨胀问题,我不知道这是否与 Butterknife 冲突。

控制台中捕获的错误:

android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class TextView
   Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class TextView
   Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 4: TypedValue{t=0x2/d=0x1010099 a=1}
       at android.content.res.TypedArray.getColor(TypedArray.java:459)
       at android.widget.TextView.<init>(TextView.java:771)
       at android.widget.TextView.<init>(TextView.java:704)
       at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:62)
       at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:58)
       at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
       at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
       at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
       at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:280)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
       at android.widget.Editor.showError(Editor.java:453)
       at android.widget.Editor.setError(Editor.java:489)
       at android.widget.TextView.setError(TextView.java:5100)
       at android.widget.TextView.setError(TextView.java:5085)
       at com.testapp.probe.mvp.ui.login.LoginActivity.onValidationFailed(LoginActivity.java:166)
       at com.mobsandgeeks.saripaar.Validator.triggerValidationListenerCallback(Validator.java:721)
       at com.mobsandgeeks.saripaar.Validator.validateFieldsWithCallbackTill(Validator.java:697)
       at com.mobsandgeeks.saripaar.Validator.validateUnorderedFieldsWithCallbackTill(Validator.java:679)
       at com.mobsandgeeks.saripaar.Validator.validate(Validator.java:334)
       at com.mobsandgeeks.saripaar.Validator.validate(Validator.java:295)
       at com.testapp.probe.mvp.ui.login.LoginActivity.validate(LoginActivity.java:141)
       at com.testapp.probe.mvp.ui.login.LoginActivity.onServerLoginClick(LoginActivity.java:107)
       at com.testapp.probe.mvp.ui.login.LoginActivity_ViewBinding$1.doClick(LoginActivity_ViewBinding.java:40)
       at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
       at android.view.View.performClick(View.java:5637)
       at android.view.View$PerformClick.run(View.java:22429)
       at android.os.Handler.handleCallback(Handler.java:751)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6119)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

源的一些重要部分:

@BindView(R.id.et_email)
@Order(1)
@NotEmpty(emptyTextResId = R.string.empty_email)
@Email(messageResId = R.string.str_email_empty)
EditText mEmailEditText;

@BindView(R.id.et_password)
@Order(2)
@NotEmpty(emptyTextResId = R.string.empty_email)
@Password(min = 4, scheme = 
Password.Scheme.ALPHA_NUMERIC_MIXED_CASE_SYMBOLS, messageResId = 
R.string.str_password_error)
EditText mPasswordEditText;

private Validator validator;
private boolean validated;

...

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

    ...

    validator = new Validator(this);
    validator.setValidationListener(this);

}

@OnClick(R.id.bt_login)
void onServerLoginClick(View v) {
    if(validate())
        mPresenter.onServerLoginClick(mEmailEditText.getText().toString(), mPasswordEditText.getText().toString());
}

protected boolean validate() {
    if (validator != null)
        validator.validate();
    return validated;           // would be set in one of the callbacks below
}

@Override
public void onValidationSucceeded() {
    validated = true;
}

@Override
public void onValidationFailed(List<ValidationError> errors) {
    validated = false;

    for (ValidationError error : errors) {
        View view = error.getView();
        String message = error.getCollatedErrorMessage(this);

        // Display error messages
        if (view instanceof Spinner) {
            Spinner sp = (Spinner) view;
            view = ((LinearLayout) sp.getSelectedView()).getChildAt(0);
        }

        if (view instanceof TextView) {
            TextView tv = (TextView) view;
            tv.setError(message);
        }

        if (view instanceof EditText) {
            EditText et = (EditText) view;
            et.setError(message);
        }

        if(view instanceof TextInputEditText) {
            TextInputEditText tiet = (TextInputEditText) view;
            tiet.setError(message);
        }


    }
}
4

1 回答 1

0

添加ButterKnife.bind(this);您的 onCreate 方法。

于 2017-05-08T08:42:23.850 回答