daniel-stoneuk / material-about-library

Makes it easy to create beautiful about screens for your apps
Apache License 2.0
1.12k stars 140 forks source link

App crashes when not setting a theme #46

Closed Syex closed 7 years ago

Syex commented 7 years ago

Hey,

first of all: great library! I wanted to use it to just show all licenses for the libraries I use. So I created a very simple Activity extending your MaterialAboutActivity:

class LicenseActivity : MaterialAboutActivity() {

   override fun getActivityTitle(): CharSequence? {
        return getString(R.string.about_title)
    }

    override fun getMaterialAboutList(context: Context): MaterialAboutList {
        val appCardBuilder = MaterialAboutCard.Builder()

        appCardBuilder.addItem(MaterialAboutTitleItem.Builder()
                .text(R.string.app_name)
                .icon(R.mipmap.ic_launcher)
                .build())

        appCardBuilder.addItem(ConvenienceBuilder.createVersionActionItem(context,
                DrawableUtil.getDrawable(context, R.drawable.ic_info_outline_black_24dp),
                getString(R.string.version),
                false));

        val butterknifeLicenseCard = ConvenienceBuilder.createLicenseCard(context,
                null,
                "Butterknife", "2013", "Jake Wharton",
                OpenSourceLicense.APACHE_2)

        return MaterialAboutList(appCardBuilder.build(),
                butterknifeLicenseCard)
    }
}

When I ran my app to try it out it crashed with

android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class TextView
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:558)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:434)
                                                       at com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter.onCreateViewHolder(MaterialAboutListAdapter.java:43)
                                                       at com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter.onCreateViewHolder(MaterialAboutListAdapter.java:21)
                                                       at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6367)

So I saw that mal_material_about_list_card.xml is causing the error. In the end it was crashing because I didn't set mal_color_primary resp. I didn't set a theme in my Activity. Adding

   override fun onCreate(savedInstanceState: Bundle?) {
        setTheme(R.style.Theme_Mal_Light_LightActionBar)
        super.onCreate(savedInstanceState)
    }

solved the problem, because it sets all of the required attributes.

While writing this I saw you write in the README to ensure setting a theme that extends one of yours. So I guess that is my own fault. Nevertheless I suggest that you check in MaterialAboutActivity if your attributes are set and, if not, fail with an explaining error message, as I'm probably not the only one that gets depressed seeing an InflateException from your layout file.

daniel-stoneuk commented 7 years ago

Sure! I'll try find some time soon. Thanks