1

I have switched my Android development over to Kotlin, but I am dealing with a crash that I can't figure out. I am used to, in Java, being able to display an error on an empty EditText:

if(mEmail.getText().toString().isEmpty()) {
   mEmail.setError("Email cannot be blank.");
}

To the best of my knowledge, that could be translated to Kotlin as:

if(email.text.toString().isEmpty()) {
   email.error = "Email cannot be blank."
}

However, that doesn't work, and I get the following stack trace:

Process: com.androidessence.capturethetag, PID: 4016
android.view.InflateException: Binary XML file line #17: Error inflating class TextView
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    at android.widget.Editor.showError(Editor.java:319)
    at android.widget.Editor.setError(Editor.java:355)
    at android.widget.TextView.setError(TextView.java:4648)
    at android.widget.TextView.setError(TextView.java:4633)
    at com.androidessence.capturethetag.activities.LoginActivity.validateInput(LoginActivity.kt:31)
    at com.androidessence.capturethetag.activities.LoginActivity.access$validateInput(LoginActivity.kt:12)
    at com.androidessence.capturethetag.activities.LoginActivity$onCreate$1.onClick(LoginActivity.kt:19)
    at android.view.View.performClick(View.java:4780)
    at android.view.View$PerformClick.run(View.java:19866)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(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)
 Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 24
    at android.content.res.TypedArray.getColor(TypedArray.java:401)
    at android.widget.TextView.<init>(TextView.java:696)
    at android.widget.TextView.<init>(TextView.java:632)
    at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
    at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:56)
    at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:92)
    at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at android.widget.Editor.showError(Editor.java:319) 
    at android.widget.Editor.setError(Editor.java:355) 
    at android.widget.TextView.setError(TextView.java:4648) 
    at android.widget.TextView.setError(TextView.java:4633) 
    at com.androidessence.capturethetag.activities.LoginActivity.validateInput(LoginActivity.kt:31) 
    at com.androidessence.capturethetag.activities.LoginActivity.access$validateInput(LoginActivity.kt:12) 
    at com.androidessence.capturethetag.activities.LoginActivity$onCreate$1.onClick(LoginActivity.kt:19) 
    at android.view.View.performClick(View.java:4780) 
    at android.view.View$PerformClick.run(View.java:19866) 
    at android.os.Handler.handleCallback(Handler.java:739) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(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) 

Any ideas why this is crashing in Kotlin?

EDIT

For more information, you can see my content_login.xml file here. I've used Gist to save space.

Also, I never call findViewById(); on my EditText because the Kotlin-Android Extension Plugin can do it, as mentioned here: https://kotlinlang.org/docs/tutorials/android-plugin.html

I have no doubts that it's referencing the right EditText, because logging showed me that it was able to determine the EditText was empty, but is unable to set the error attribute.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
AdamMc331
  • 16,492
  • 10
  • 71
  • 133
  • @LinX64 I will try to add more info for the non-Kotlin people in here haha. – AdamMc331 Jan 31 '16 at 17:36
  • possible duplicate of http://stackoverflow.com/questions/26524048/upgrading-to-sdk-21-error-inflating-class-android-support-v7-internal-widget-a – activedecay Jan 31 '16 at 17:59
  • 2
    @activedecay I looked at those answers and it's not *quite* the same issue, but I tried taking out my theme for the TextInputLayout and it appears I did do something incorrect in styles.xml. I will play with it to figure out what and let you know. Thanks! – AdamMc331 Jan 31 '16 at 18:12
  • 1
    It seems to be an issue with inflating the view in question, not Kotlin related. Particularly the crash happens when it tries to resolve some color attribute. Include this view's XML definition in your question. – Matt Sams Feb 01 '16 at 15:32
  • @deadpixelsociety Yeah, I realized that as well, I haven't had a moment yet to update the question accordingly. I will do soon and let you know once it's updated. – AdamMc331 Feb 01 '16 at 15:53
  • Have you tried doing a clean build? I just tested this and it works for me. I would be surprised if this is a kotlin issue. Also, there's a slim chance it could be caused by having a dependency issue where you have multiple versions of support libraries included. – Brenton Feb 01 '16 at 23:40

0 Answers0