Office Hours — Today, June 23

Thursday, June 21

Jun 23
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Gabriele
has entered the room
Mark M.
hello, Gabriele!
how can I help you today?
Gabriele
Hello Mark! So much time, how are you?
Mark M.
OK, and you?
Gabriele
I'm fine, too, thanks! I'm playing with DayNight themes on Android 4 and higher. Everything is working fine, but android:drawable on item selector is causing a crash
any idea of the reason?
Mark M.
what is the exception, and what code is triggering the crash?
Gabriele
I tell you in a moment :)
4:00 PM
Gabriele
this is the line causing the crash: <item android:state_activated="true" android:drawable="?attr/colorPrimary" />
(launching the emulator...)
Mark M.
I have not tried using a color for `android:drawable` -- are you sure that is supported?
Gabriele
If I use @color it's working, so I thought it is
View paste (134 more lines)
   android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
    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 com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at eu.davidea.flexibleadapter.FlexibleAdapter.onCreateViewHolder(FlexibleAdapter.java:1742)
        at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6685)
        at android
...
and this is the stack error
Mark M.
if you're sure that is the line causing this error, then it feels like it cannot find the resource associated with `?attr/colorPrimary`
(ugh, ignore the failed Markdown formatting...)
Gabriele
then maybe it is my fault, let me check
4:15 PM
Ahmad M.
has entered the room
Mark M.
hello, Ahmad!
Ahmad M.
hello Mark
Mark M.
Gabriele: let me take a question from Ahmed, and I will return to you in a bit
Ahmad: your turn! do you have a question?
Ahmad M.
yes
Mark M.
Ahmad: OK, go ahead!
Ahmad M.
is learning Android’s Architecture Components is importante
Mark M.
it depends a lot on what sorts of apps you wish to write
games, for example, will not use the Architecture Components much
for more "traditional" types of apps, the Architecture Components can be useful
plus, Google will be promoting them very heavily, and so they will be difficult to avoid in some cases
Ahmad M.
ok , i need to use Room Database in my app ,but i have my own SQLite Databse how can i use Room that way ?
Mark M.
you would need to adapt your app to use Room to manage your existing tables
that may be tricky to get right, particularly if your app is already in the hands of users
4:20 PM
Mark M.
Room and other ORMs are easier to use if you start with them, rather than switching to them on an existing project
if there are specific problems that you feel Room will solve for you, where those solutions are worth the effort to change your app, then go ahead and try switching to Room
Ahmad M.
i don't need the users to add info to the database i have the database with it's info
Mark M.
OK, so you are packaging the database with the app? or are you downloading the database from your server?
Ahmad M.
is Room a good platform for that ?
Mark M.
it can be
for example, I have a chapter in my "Android's Architecture Components" book that covers how to package a Room database with an app
Ahmad M.
i think it's new and it may have a lot of Bugs and u know
Mark M.
if you have existing code that works and you like it, then there may be no reason to adopt Room
only change working code if there is something that you expect to gain from the change
4:25 PM
Mark M.
let me take another question from Gabriele, and I will return to you in a little while
Gabriele: back to you! do you have another question?
Gabriele
I'm looking at this item, but to me it seems it can find it (at least in Android Studio), any way to check if this is the problem?
Ahmad M.
that lock good to me thank you for your time (:
Mark M.
Gabriele: try switching from ?attr/colorPrimary to a reference to a color resource or something
Ahmad: you're welcome!
Ahmad M.
has left the room
Gabriele
I have tried with a color resource, but the same happens
Mark M.
you mean, you get the same crash with the same basic stack trace?
Gabriele
no sorry, with the @color it is working
but then how can I handle different colors based on the theme day/night?
Mark M.
well, I have not played with DayNight themes, so I do not know the specifics of that scenario
it is possible that a StateListDrawable cannot support ?attr syntax
or, it is possible that the syntax is fine, but for some reason ?attr/colorPrimary does not exist in both the day and night themes(?)
4:30 PM
Gabriele
what I would like to achieve is change the background of the selected row of my recyclerview based on the theme
colorPrimary exists
Mark M.
I have not tried using ?attr syntax in a drawable resource, and I have not tried DayNight theme support, so I am not really in position to give you a concrete solution
you might consider trying two drawable resources, instead of one with ?attr, and apply the drawables on a per-theme basis
so, you have a day background, and a night background, and your layout chooses the right one based on some theme setti
er, setting
Gabriele
so loading it from code
Mark M.
no, it could be android:background="?attr/selectorBackground" or something, for some custom theme attribute of yours, I presume
Gabriele
I have tried using android:background, but it still crashes
Mark M.
were you using android:background with a drawable resource with an ?attr value in it, as in the code from earlier in the chat?
or were you using android:background="?attr/..."?
Gabriele
I was using ?attr/
4:35 PM
Mark M.
in the drawable, or in the layout?
Gabriele
in the layout
Mark M.
OK, that should work -- perhaps you were getting a different error in the crash
using ?attr/ syntax in layouts is done fairly often
Gabriele
View paste (198 more lines)
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
    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 com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at eu.davidea.flexibleadapter.FlexibleAdapter.onCreateViewHolder(FlexibleAdapter.java:1742)
        at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6685)
        at android.su
...
this is using ?colorPrimary
now I'm trying with android:background=
View paste (198 more lines)
06-23 22:38:06.611 7693-7693/net.fr0g.mchat E/AndroidRuntime: FATAL EXCEPTION: main
    Process: net.fr0g.mchat, PID: 7693
    android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
    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 com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at eu.davidea.flexibleadapter.FlexibleAdapter.onCreateViewHolder(FlexibleAdapter.java
...
Mark M.
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: <item> tag requires a 'drawable' attribute or child tag defining a drawable
this goes back to my wondering if a color resource works in an <item> in a drawable
Gabriele
but using @color/mycolor it works
4:40 PM
Mark M.
then use @color/mycolor, and have two separate drawables (day, night)
4:40 PM
Gabriele
ok, I'll do like that, thanks
this way it's working
4:45 PM
Mark M.
OK
Gabriele
thanks again :)
Mark M.
you are very welcome!
4:55 PM
Gabriele
see you next time, Mark!
Gabriele
has left the room
5:00 PM
Mark M.
turned off guest access

Thursday, June 21

 

Office Hours

People in this transcript

  • Ahmad Mustafa
  • Gabriele
  • Mark Murphy