Calligraphy
Calligraphy copied to clipboard
Crash when using labelFor attribute on TextView
Hi there,
Setting the labelFor attribute on TextView elements seems to stop Calligraphy from inflating layouts. Potentially down to the fact labelFor accepts a resource ID?
Trace:
04-27 11:06:21.819 23171-23171/com.greatfridays.rtp E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.greatfridays.rtp, PID: 23171 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.greatfridays.rtp/com.greatfridays.rtp.activities.HomeActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class TextView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) at android.app.ActivityThread.access$900(ActivityThread.java:161) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class TextView at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719) at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60) at android.view.LayoutInflater.inflate(LayoutInflater.java:398) at android.view.LayoutInflater.inflate(LayoutInflater.java:354) at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228) at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102) at com.greatfridays.rtp.activities.HomeActivity.onCreate(HomeActivity.java:23) at android.app.Activity.performCreate(Activity.java:5426) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) at android.app.ActivityThread.access$900(ActivityThread.java:161) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method) Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x2 at android.content.res.Resources.getResourceEntryName(Resources.java:2746) at uk.co.chrisjenx.calligraphy.CalligraphyFactory.matchesResourceIdName(CalligraphyFactory.java:112) at uk.co.chrisjenx.calligraphy.CalligraphyFactory.isActionBarTitle(CalligraphyFactory.java:75) at uk.co.chrisjenx.calligraphy.CalligraphyFactory.getStyleForTextView(CalligraphyFactory.java:51) at uk.co.chrisjenx.calligraphy.CalligraphyFactory.onViewCreatedInternal(CalligraphyFactory.java:165) at uk.co.chrisjenx.calligraphy.CalligraphyFactory.onViewCreated(CalligraphyFactory.java:133) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:170) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:146) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700) at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60) at android.view.LayoutInflater.inflate(LayoutInflater.java:398) at android.view.LayoutInflater.inflate(LayoutInflater.java:354) at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228) at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102) at com.greatfridays.rtp.activities.HomeActivity.onCreate(HomeActivity.java:23) at android.app.Activity.performCreate(Activity.java:5426) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) at android.app.ActivityThread.access$900(ActivityThread.java:161) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method)
Thanks, Dave
OK thanks, I'll investigate.
I have the simmilar problem. I inflate layout manually:
View view = inflate(getContext(), R.layout.my_layout, null);
my_layout.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:labelFor="@+id/my_edit_text"
android:text="@string/my_edit_text_label" />
<EditText
android:id="@+id/my_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</LinearLayout>
When I remove TextView
's android:labelFor
attribute, it works fine.
There is a problem with generating new IDs.
Stacktrace below:
android.view.InflateException: Binary XML file line #7: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
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 android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.view.View.inflate(View.java:18539)
at ...
at android.view.View.performClick(View.java:4781)
at android.view.View$PerformClick.run(View.java:19873)
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: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:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x2
at android.content.res.Resources.getResourceEntryName(Resources.java:2265)
at uk.co.chrisjenx.calligraphy.CalligraphyFactory.matchesResourceIdName(CalligraphyFactory.java:89)
at uk.co.chrisjenx.calligraphy.CalligraphyFactory.isActionBarTitle(CalligraphyFactory.java:52)
at uk.co.chrisjenx.calligraphy.CalligraphyFactory.getStyleForTextView(CalligraphyFactory.java:28)
at uk.co.chrisjenx.calligraphy.CalligraphyFactory.onViewCreatedInternal(CalligraphyFactory.java:142)
at uk.co.chrisjenx.calligraphy.CalligraphyFactory.onViewCreated(CalligraphyFactory.java:110)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:172)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:148)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
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 android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.view.View.inflate(View.java:18539)
at ...
at android.view.View.performClick(View.java:4781)
at android.view.View$PerformClick.run(View.java:19873)
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: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:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Still have this issue
Still happens.
Still happens.
I know. Has anyone actually found out what the issue is?
On Wed, 27 Jul 2016, 04:50 Arthur, [email protected] wrote:
Still happens.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/160#issuecomment-235477229, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRsY3VbOVHMxSQUgfNAsj5H8ytuc0cks5qZtWggaJpZM4EJhxx .
Setting labelFor forces the view to has id generated in runtime (android.view.View#setLabelFor) CaligraphyFactory:89 checks if there is resource for view id. If the view has generated id, this check would throw reported exception.
Workaround:
use labelFor
with id
so no id generation would have to happen.
Suggested solution: do not assume resource name lookup for id would always return valid resource.
OK great, thanks for that, much clearer now.
On Fri, 12 Aug 2016, 13:43 Dominik Barwacz, [email protected] wrote:
Setting labelFor forces the view to has id generated in runtime (android.view.View#setLabelFor) CaligraphyFactory:89 checks if there is resource for view id. If the view has generated id, this check would throw reported exception.
Workaround: use labelFor with id so no id generation would have to happen.
Suggested solution: do not assume resource name lookup for id would always return valid resource.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/160#issuecomment-239436147, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRsRWHhJtZ0gHriMshPjoBtu1sx2NIks5qfGpugaJpZM4EJhxx .
Still having this issue. Please - at least put it to README if it is too difficult to fix, I wasted hours on this bug.
Me too
@xawill @jehy instead of doing:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:labelFor="@+id/my_edit_text"
android:text="@string/my_edit_text_label" />
you have to do this:
<TextView
android:id="@+id/some_id_so_that_it_does_not_crashes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:labelFor="@+id/my_edit_text"
android:text="@string/my_edit_text_label" />
so, you only need to add an ID in order to not crash
@yombunker we resolved this issue for ourselves monthes ago. The problem is that
- This problem exists in the first place
- It is not described in repository readme
@jehy I couldn't have hoped for less than that, but, still nobody had posted the solution is simple words and example, so, if someone else faces the issue I wanted to be there documented :)