扩展类android.support.v7.widget.AppCompatEditText时出错

时间:2016-03-09 09:24:01

标签: android android-appcompat

我正在尝试使用带有EditText的android.support.design.widget.TextInputLayout进行密码输入。一旦密码输入出现问题,TextInputLayout就会显示错误消息。

  

当我使用EditText时,setError(字符串)出现崩溃。

日志:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infibond.infi/com.infibond.account.login.LoginActivity}: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
       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(Method.java)
       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(NativeStart.java)
Caused by java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
       at android.content.res.TypedArray.getColor(TypedArray.java:327)
       at android.widget.TextView.<init>(TextView.java:700)
       at android.widget.TextView.<init>(TextView.java:635)
       at android.widget.TextView.<init>(TextView.java:631)
       at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:380)
       at com.infibond.account.login.LoginFragment.onCreateView(LoginFragment.java:94)
       at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
       at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
       at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
       at com.infibond.base.Inheritance.Activities.ActivityBase.onStart(ActivityBase.java:112)
       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
       at android.app.Activity.performStart(Activity.java:5421)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2279)
       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(Method.java)
       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(NativeStart.java)
  

我尝试切换到AppCompatEditText,但出于某种原因,在某些设备中(例如:华硕TOOJ,华硕ZOO2),我的应用程序崩溃了。

日志:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infibond.infi/com.infibond.account.login.LoginActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.v7.widget.AppCompatEditText
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
       at android.app.ActivityThread.access$800(ActivityThread.java:147)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5253)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by android.view.InflateException: Binary XML file line #22: Error inflating class android.support.v7.widget.AppCompatEditText
       at android.view.LayoutInflater.createView(LayoutInflater.java:633)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:211)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       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 uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at com.infibond.account.login.LoginFragment.onCreateView(LoginFragment.java:91)
       at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
       at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
       at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
       at com.infibond.base.Inheritance.Activities.ActivityBase.onStart(ActivityBase.java:112)
       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
       at android.app.Activity.performStart(Activity.java:5991)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2279)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
       at android.app.ActivityThread.access$800(ActivityThread.java:147)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5253)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

代码:

private void formValidatorHandler() {
    if (NetworkManager.getConnectivityStatus(getActivity()) == NetworkManager.NETWORK_STATUS_NOT_CONNECTED) {
        new MyToast(getActivity(), getString(R.string.error_internet_connection_title), MyToast.KEY_TYPE_RED).show();
            return;
    }

    if (!((AccountBaseActivity) getActivity()).isValidPassword(mEtPassword.getText().toString())) {
            String passwordError = getString(R.string.error_account_invalid_Password);
            mPasswordwrapper.setError(passwordError);
            //AndroidUtils.showToast(passwordError, Toast.LENGTH_SHORT);
            return;
    } else {
            mPasswordwrapper.setError("");
    }

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String freshInstall = preferences.getString(Constant.Prefs.SP_KEY_FRESH_INSTALL, LoginRequest.FRESH_INSTALL_TRUE);

    ProgressBarClass.startLoading(getActivity());

    new LoginRequest(getActivity(), mEtUserName.getText().toString().trim(),
                mEtPassword.getText().toString().trim(),
                freshInstall,
                true, ((LoginActivity) getActivity()));
}

xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <include android:id="@+id/loginInfiLogoRL"
        layout="@layout/login_infi_logo_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="-3dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="10dp"/>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/loginInfiLogoRL"
        android:theme="@style/TextLabel">

        <android.support.v7.widget.AppCompatEditText
            android:id="@+id/etUserName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/login_screen_email_hint"
            android:imeOptions="actionNext"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:nextFocusDown="@+id/etPassword"
            android:singleLine="true"
            android:textColor="@color/white"
            android:textColorHighlight="@color/Orange"
            android:textColorHint="@color/white" />
    </android.support.design.widget.TextInputLayout>
</RelativeLayout>

我的应用程序gradle

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
//apply plugin: 'newrelic'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.jakewharton.hugo'

android {

compileSdkVersion 23
buildToolsVersion "23.0.1"

signingConfigs {
    Signing_Prod {
        keyAlias 'infi'
        keyPassword 'infi1234'
        storeFile file('../release.keystore/infi.jks')
        storePassword 'infi1234'
    }
}

lintOptions {
    abortOnError false
}

defaultConfig {
    applicationId "com.infibond.infi"
    minSdkVersion 18
    targetSdkVersion 22
    versionCode 113
    versionName "1.0.1"
    multiDexEnabled true //fixes gradle issue
}

buildTypes {
    debug {
}

    release {
        shrinkResources true
        minifyEnabled false
        //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.Signing_Prod
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

packagingOptions {
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/LICENSE.txt'
}

dexOptions {
    jumboMode true
    incremental true
    preDexLibraries false
    javaMaxHeapSize "4g"
}
/*
        configurations {
            all*.exclude group: 'com.android.support', module: 'support-v4'
        }*/

sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/']         }     }
 }

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url 'https://maven.fabric.io/public' }
}


dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//TODO: ----------------- Media Chooser Lib ---------------------- //
compile project(':mediaChooserlib')
//TODO: ----------------- Upload Service Lib --------------------- //
compile project(':uploadservice')
//TODO: ----------------- Meta Data Extractor -------------------- //
compile files('libs/metadata-extractor-2.6.4.jar')
//TODO: ----------------- JakeWharton Disk LRU Cache ------------- //
compile 'com.jakewharton:disklrucache:2.0.2'
//TODO: ----------------- FFmpeg Meta Data Retriver -------------- //
compile 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.2'
//TODO: ----------------- Support -------------------------------- //
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
//TODO: ----------------- Google Play ---------------------------- //
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.apis:google-api-services-tasks:v1-rev41-1.20.0'
//TODO: ----------------- Google Drive --------------------------- //
compile ('com.google.api-client:google-api-client-android:1.20.0') /*{
    exclude module: 'httpclient' //by artifact name
    exclude group: 'org.apache.httpcomponents' //by group
    exclude group: 'org.apache.httpcomponents', module: 'httpclient' //by both name and group
}*/
compile 'com.google.apis:google-api-services-drive:v2-rev170-1.20.0'
//TODO: ----------------- GSON ----------------------------------- //
compile 'com.google.code.gson:gson:2.3'
//TODO: ----------------- Creative SDK --------------------------- //
compile 'com.adobe.creativesdk:image:4.0.0'
//TODO: ------- Android Transcoder (Media Compression) SDK ------- //
compile 'net.ypresto.androidtranscoder:android-transcoder:0.1.9'
//TODO: ----------------- Active Android ------------------------- //
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
//TODO: ----------------- Volley --------------------------------- //
compile 'com.mcxiaoke.volley:library:1.0.17'
//TODO: ----------------- Glide ---------------------------------- //
compile 'com.github.bumptech.glide:glide:3.7.0'
//TODO: ----------------- Bus Libs ------------------------------- //
compile 'com.squareup:otto:1.3.8'
compile 'de.greenrobot:eventbus:2.4.0'
//TODO: ----------------- PhotoView - photo zoom lib ------------- //
compile 'com.commit451:PhotoView:1.2.4'
//TODO: ----------------- AutoFit TextView ----------------------- //
compile 'me.grantland:autofittextview:0.2.1'
//TODO: ----------------- Custom Font Lib -------------------------//
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
//TODO: ----------------- New Relic analytics & tracking --------- //
//compile 'com.newrelic.agent.android:android-agent:4.+'
//TODO: ----------------- Crashlytics ---------------------------- //
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
    transitive = true;
}

//TODO: ================= Social Networks ======================== //
//TODO: ----------------- Sound Cloud ---------------------------- //
//compile 'com.soundcloud.android:android-crop:1.0.1@aar'
//TODO: ----------------- Facebook ------------------------------- //
compile 'com.facebook.android:facebook-android-sdk:4.4.0'
//TODO: ----------------- Twitter -------------------------------- //
//compile 'org.twitter4j:twitter4j-core:4.0.4'
//TODO: ----------------- YouTube - re-write to newer version ---- //
compile files('libs/YouTubeAndroidPlayerApi.jar')
//TODO: ----------------- DropBox -------------------------------- //
//compile files('libs/dropbox-android-sdk-1.6.3.jar')

//================== UNKNOWN =============================== //
//compile files('libs/json_simple-1.1.jar')
//================== KNOWN - NOT USED ====================== //
//----------------- Scroll View Tricks---------------------- //
//compile files('libs/scrollviewtricks.jar')
//----------------- StaggeredGrid
//compile 'com.etsy.android.grid:library:1.0.5'
//----------------- Tumblr
//compile 'com.tumblr:jumblr:0.0.11'
//compile 'com.crittercism:crittercism-android-agent:5.0.6'
//compile 'com.edmodo:cropper:1.0.1'
//apply plugin: 'com.google.gms.google-services'

// --------------------- Progress Bars ----------------------
compile 'com.mikhaellopez:circularprogressbar:1.1.0'
}

0 个答案:

没有答案