I have a main app which has a dependency to a android libary. I have an activity in android library. I verified the layout file and activity class. Activity class is make a call to right layout file. But I don't know for some reason, I am not able to call the library's activity from main app. Dependency wise, I verified everything. I have another library as well which main app depend on but that library works gr8 without any issues. For this library, I keep getting,
java.lang.RuntimeException: Unable to start activity ComponentInfo{}: android.content.res.Resources$NotFoundException: Resource ID #0x7f03001a
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2451)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5499)
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:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f03001a
at android.content.res.Resources.getValue(Resources.java:1266)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2656)
at android.content.res.Resources.getLayout(Resources.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at XXXXXXXXXXXX.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1117)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2451)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5499)
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:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
I imported package specific R file in activity and issue gone. Thanks for everyone for your time.
Related
There are some apps that read from this folder without any root access,I know some of the folders in /data requires root access,but I think this /data/app does not(there are some app that constantly access the data(s) inside it,like shareit,or any apk backup/share app),but I am always getting Exceptoions if I try to read or access any file/folder in /data/app folder. Please help. The code and the exceptions are bellow:
File[] files=new File("/data/app").listFiles();
for(int i=0;i<files.length;++i) {
System.out.println(files[i].getAbsolutePath());
}
Exceptions:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ragib.app_from_scratch, PID: 9293
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ragib.app_from_scratch/com.example.ragib.app_from_scratch.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
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.NullPointerException: Attempt to get length of null array
at com.example.ragib.app_from_scratch.MainActivity.onCreate(MainActivity.java:43)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
I used FX file explorer to see if the folder is empty, but it was not, there was some folders(as some apps were installed). But I was unable to list those by my code.
Please have a look.
Thanks...
Screenshots are bellow(see the links)
Inside /data/app folder
Inside /data/app/com.facebook... folder, i even copied it from here to my sd card
Can't load a layout, activity fails on: setContentView
the "missing" resource is the activity layout itself found under layout folder
Activity extends FragmentActivity
the device: HTC M9 running marshmallow
stack trace:
Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{MyActivty}:
android.content.res.Resources$NotFoundException: File Share with %s from xml type layout resource ID #0x7f0a001d
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2484)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: android.content.res.Resources$NotFoundException: File Share with %s from xml type layout resource ID #0x7f0a001d
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2836)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2791)
at android.content.res.Resources.getLayout(Resources.java:1173)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:411)
at android.app.Activity.setContentView(Activity.java:2177)
at packageName.MyActivty.onCreate(MyActivty.java:43)
at android.app.Activity.performCreate(Activity.java:6248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.io.FileNotFoundException: Share with %s
at android.content.res.AssetManager.openXmlAssetNative(Native Method)
at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:508)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2818)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2791)
at android.content.res.Resources.getLayout(Resources.java:1173)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:411)
at android.app.Activity.setContentView(Activity.java:2177)
at packageName.MyActivity.onCreate(MyActivty.java:43)
at android.app.Activity.performCreate(Activity.java:6248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
12-24 17:43:16.037 10054-10054/com.deepinstinct.android.dev.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.deepinstinct.android.dev.debug, PID: 10054
java.lang.RuntimeException: Unable to start activity ComponentInfo{packageName/packageName.MyActivity}:
android.content.res.Resources$NotFoundException: File Share with %s from xml type layout resource ID #0x7f0a001d
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2484)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: android.content.res.Resources$NotFoundException: File Share with %s from xml type layout resource ID #0x7f0a001d
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2836)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2791)
at android.content.res.Resources.getLayout(Resources.java:1173)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:411)
at android.app.Activity.setContentView(Activity.java:2177)
at packageName.MyActivity.onCreate(MyActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.io.FileNotFoundException: Share with %s
at android.content.res.AssetManager.openXmlAssetNative(Native Method)
at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:508)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2818)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2791)
at android.content.res.Resources.getLayout(Resources.java:1173)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:411)
at android.app.Activity.setContentView(Activity.java:2177)
at packageName.MyActivity.onCreate(MyActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
I have never seen this error: File Share with %s from xml type layout resource
how can i fix this?
solved it:
I had an android library loaded to my project by reflection. the specified resource in the stack trace: 0x7f0a001d (my layout id) was a resource id of an appcompat component in the loaded library and the resources conflicted.
brute force solution:
create a unique layout id for my layout that doesn't conflict with the loaded library's one (by copy-pasting the original layout). obviously not the best solution
actual solution that worked for me:
the loaded library is all code and there is no native android functionality, so I have removed the appcompat v7 support library from the .gradle, making the conflicting resource to disappear
I am trying to use the Linphone library for Android. I have installed all the libraries as specified and when I am trying to run the project, I am getting the below error.
Process: org.linphone, PID: 13440
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.linphone/org.linphone.LinphoneLauncherActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0a003b type #0x5 is not valid
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
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: android.content.res.Resources$NotFoundException: Resource ID #0x7f0a003b type #0x5 is not valid
at android.content.res.Resources.getBoolean(Resources.java:999)
at org.linphone.LinphoneLauncherActivity.onCreate(LinphoneLauncherActivity.java:50)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
Please let me know how can I resolve this as my work is stuck because of this.
Thanks in advance !!.
Regarding this ans:
Android Resources$NotFoundException: Resource ID #0x7f030027
You can check your R file for Resources$NotFoundException: Resource ID #0x7f030027. It'll tell you which resource was creating problem. As an alternative sollution I think you might have setText or any content just an int.And as you know here compiler will look for corresponding resource value. So, just concat an empty string there as ""
The app was just working fine and then I added a new Activity and it started giving me this error. I have tried setting the theme to app compat theme and also using app compat activity. Still nothing working.
Process: info.androidhive.loginandregistration, PID: 28764
java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.loginandregistration/info.androidhive.loginandregistration.activity.MainScreenActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at info.androidhive.loginandregistration.activity.MainScreenActivity.onCreate(MainScreenActivity.java:69)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:185)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:179)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at info.androidhive.loginandregistration.activity.MainScreenActivity.onCreate(MainScreenActivity.java:69)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library
My guess is that:
When you first created the app, and you created the first activity in the new-project wizard, you unchecked the "Make Backwards Compatible (AppCompat)" checkbox
When you added your new activity, you did so via the new-activity wizard, and this time you left that checkbox checked
Your overall application theme will not use Theme.AppCompat, because you opted out of appcompat-v7 by unchecking that checkbox. Your new activity is extending AppCompatActivity, but it is still using the application theme, and that is a conflict that would generate the error.
Tactically, change your new MainScreenActivity to have it extend from Activity, not AppCompatActivity. You may need to make some other adjustments depending on what activity template you chose and what resources it created (e.g., change app: to android: on attributes in menu resources).
Strategically, you need to decide whether you want to use appcompat-v7 or not, then stick with that choice for this project. Using appcompat-v7 gives you a somewhat consistent look-and-feel across Android versions (back to API Level 14), at the cost of your app being ~1MB bigger and some additional complexity when writing the app.
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.