Search code examples
androidkotlinbottomnavigationviewinflate-exceptionlayout-animation

Text view contents not appearing on the phone screen in android using Kotlin


I am unable to display the textviews and their contents on screen. The app does not crash but the debugger console displays this error. It shows that the causes are the following.

Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.RuntimeException: Unknown layout animation name: accelerateInterpolator

Moreover, the error points to setcontentview in the MainActivity. I have attempted solutions to the issue but to no progress. In fact I have higher version but this the error persists.

The build.gradle(Module:app) contents are

//noinspection GradleCompatible
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.vishwa.imaginators"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        debuggable false
        shrinkResources false
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        zipAlignEnabled true
    }
  }
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
//noinspection GradleCompatible
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.squareup.okhttp:okhttp:2.4.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'

//retrofit
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.0.0'
//    implementation "com.squareup.retrofit2:converter-moshi:2.0.0"
//rxjava
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
//download sdk
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation 'com.facebook.android:facebook-login:[4,5)'
implementation 'com.squareup.picasso:picasso:2.3.2'
}

The activity_main.xml is shown below.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
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"
android:background="@mipmap/bg"
tools:context=".MainActivity">

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_nav"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@color/nav_item_colors"
    app:itemTextColor="@color/nav_item_colors"
    app:menu="@menu/bottom_navigation">

</android.support.design.widget.BottomNavigationView>

<FrameLayout
    android:id="@+id/main_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/bottom_nav"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview_Main"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v7.widget.RecyclerView>
  </FrameLayout>

</RelativeLayout>

A snippet of the code that where I am adding the contents to this fragment.

bottomNavigationView.setOnNavigationItemSelectedListener { item ->
        when(item.itemId){
            R.id.nav_progress->
                progressData()
            R.id.nav_discover->
                discoverData(arrItems)
            R.id.nav_concept->
                fetchData(arrItems, indices)
           }
        true
    }

    private fun progressData() {

    var titles = listOf("first","second", "third","fourth")
    val text1=findViewById<TextView>(R.id.quadrant1_textview1)
    val text2=findViewById<TextView>(R.id.quadrant2_textview1)
    val text3=findViewById<TextView>(R.id.quadrant3_textview1)
    val text4=findViewById<TextView>(R.id.quadrant4_textview1)
    text1?.text=titles[0]
    text2?.text=titles[1]
    text3?.text=titles[2]
    text4?.text=titles[3]
    }

The ProgressData() funtion is outside the oncreate.

Any help is appreciated.


Solution

  • The solution to this problem is that the view is not generated in the onCreate or OnCreateview. If we see the life-cycle of the fragment, we find that there is another method onViewcreated. The static code where the values are assigned to the text of the textviews must be placed in the onViewcreated method of the Progress fragment. This solved the problem.

    The code snippet:

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        progress_progressbar2?.setProgress(12)
        progress_progressbar2?.max=15
        val currentProgress = progress_progressbar2?.progress ?: 0
        if (currentProgress == 0){
            started_image?.visibility = View.VISIBLE
            progress_scrollview?.invalidate()
        } else {
            started_image?.visibility = View.GONE
            progress_scrollview?.visibility = View.VISIBLE
            navigation_header_container?.setImageResource(R.drawable.header_pink)
        }
    }
    

    Thankyou YoLo for support. This worked for me.