0

I finished my first Android application 2 week ago and published on Play Store. When I look through Android Vitals(Anrs&Crash), I see some crashes for different type Android devices. But I could not reproduce this crash on real device or simulator.

Crash Log on Play Store

android.view.InflateException: at android.view.LayoutInflater.inflate (LayoutInflater.java:551) at android.view.LayoutInflater.inflate (LayoutInflater.java:429) at com.ehliyetcepte.ehliyet.sinav.sorulari.Adapter.MenuAdapter.onCreateViewHolder (MenuAdapter.java:11) at com.ehliyetcepte.ehliyet.sinav.sorulari.Adapter.MenuAdapter.onCreateViewHolder (MenuAdapter.java:11) at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder (RecyclerView.java) at androidx.recyclerview.widget.RecyclerView$Adapter.getItemCount (RecyclerView.java) at androidx.recyclerview.widget.RecyclerView$Adapter.getItemViewType (RecyclerView.java) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:64) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5) at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:5) at androidx.recyclerview.widget.GridLayoutManager.assignSpans (GridLayoutManager.java) at androidx.recyclerview.widget.GridLayoutManager.checkLayoutParams (GridLayoutManager.java) at androidx.recyclerview.widget.GridLayoutManager.collectPrefetchPositionsForLayoutState (GridLayoutManager.java) at androidx.recyclerview.widget.GridLayoutManager.findReferenceChild (GridLayoutManager.java) at androidx.recyclerview.widget.GridLayoutManager.generateLayoutParams (GridLayoutManager.java) at androidx.recyclerview.widget.GridLayoutManager.generateLayoutParams (GridLayoutManager.java)*

And main.xml file

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <RelativeLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorRed"
        android:orientation="vertical"
        app:layout_constraintTop_toTopOf="parent">

        <Button
            android:id="@+id/instagramClicked"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginStart="0dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/icon_instagram" />

        <Button
            android:id="@+id/facebookClicked"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/icon_facebook"/>
    </RelativeLayout>
    <RelativeLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="200dp"
        android:background="@color/colorRed"
        android:orientation="vertical"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewMenu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical" />
    </RelativeLayout>

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:background="@drawable/ehliyet_80_transparan"
        android:contentDescription="Logo"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_weight="1"
        android:text="ehliyetCepte"
        android:contentDescription="ehliyetCepte"
        android:textColor="@color/colorWhite"
        android:textSize="25sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

    <Button
        android:id="@+id/start"
        style="@style/AppTheme.RoundedCornerMaterialButton"
        android:layout_width="150dp"
        android:layout_height="55dp"
        android:layout_marginTop="100dp"
        android:text="SINAVA BAŞLA"
        android:textColor="@color/colorRed"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

And MainActivity.kt

import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.StrictMode
import android.os.StrictMode.VmPolicy
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ehliyetcepte.ehliyet.sinav.sorulari.Adapter.MenuAdapter
import com.ehliyetcepte.ehliyet.sinav.sorulari.Data.MenuModel
import com.emregurses.babysleep.Common.Common
import com.emregurses.babysleep.Common.SpacesItemDecoration
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

    lateinit var adapter: MenuAdapter
    lateinit var itemList: MutableList<MenuModel>
    lateinit var recycle_view: RecyclerView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        recycle_view = findViewById(R.id.recyclerViewMenu) as RecyclerView
        initData()
        setData()

        instagramClicked.setOnClickListener {
            val uri = Uri.parse("http://instagram.com/_u/ehliyetapp")
            val likeIng = Intent(Intent.ACTION_VIEW, uri)

            likeIng.setPackage("com.instagram.android")

            try {
                startActivity(likeIng)
            } catch (e: ActivityNotFoundException) {
                startActivity(
                    Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse("http://instagram.com/ehliyetapp")
                    )
                )
            }
        }

        facebookClicked.setOnClickListener {
            val uri = Uri.parse("https://www.facebook.com/ehliyetcepte")
            val likeIng = Intent(Intent.ACTION_VIEW, uri)

            likeIng.setPackage("com.facebook.katana")

            try {
                startActivity(likeIng)
            } catch (e: ActivityNotFoundException) {
                startActivity(
                    Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse("https://www.facebook.com/ehliyetcepte")
                    )
                )
            }
        }
    }

    private fun setData() {

        if (this != null) {
            adapter = MenuAdapter(this, itemList)

            val layoutManager = GridLayoutManager(this, Common.NUM_OF_COLUMN)
            layoutManager.orientation = RecyclerView.VERTICAL
            layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup(){
                override fun getSpanSize(i: Int): Int {
                    return if(adapter != null){
                        when(adapter!!.getItemViewType(i)){
                            1 -> 1
                            0 -> Common.NUM_OF_COLUMN
                            else -> -1
                        }
                    } else {
                        -1
                    }
                }
            }

            recycle_view.layoutManager = layoutManager
            recycle_view.addItemDecoration(SpacesItemDecoration(8))
            recycle_view.adapter = adapter
        }
    }

    private fun initData() {
        itemList = ArrayList()
        itemList.add(MenuModel(R.drawable.img_review , "Exams",1))
        itemList.add(MenuModel(R.drawable.img_sss , "Exams 2",2))
        itemList.add(MenuModel(R.drawable.img_traffic_light , "Exams 3",3))
        itemList.add(MenuModel(R.drawable.img_appreview , "Exams 4",4))
    }
}
Vega
  • 27,856
  • 27
  • 95
  • 103
Emre Gürses
  • 1,992
  • 1
  • 23
  • 28
  • 1
    This is related to `androidx`. To reproduce it you probably need a device with adequate Android. Maybe your user is using older version of Android. – Martin Berger Jun 04 '20 at 21:24
  • Yes, this crash got an older android divece such as Samsung j3, j5. But I dont know how can I resolve this issue. Some android devices got error when app opening. – Emre Gürses Jun 05 '20 at 08:17
  • I do not know.. The issue is too broad, it would require that I debug the app. I recommend that you install crash reporting tool like Firebase Crashlytics and get detailed info. To fix this you first need to be able to reproduce it. When you are able to reproduce it, fix it. You can use simulators to run older Android versions. – Martin Berger Jun 05 '20 at 11:11

0 Answers0