0

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.

Eswar
  • 1,201
  • 19
  • 45

2 Answers2

0

Try following code hope this will help:

<?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"
    tools:context=".MainActivity">


    <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="wrap_content">

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

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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>


</RelativeLayout>
yogesh lokhande
  • 1,245
  • 1
  • 11
  • 20
  • You just swapped the Framelayout and the bottomnavigationview. Also changed the recyclerview height to wrap content. Well I want it to match parent.This hasn't worked. – Eswar Jul 26 '18 at 10:30
  • Now it shows E/RecyclerView: No adapter attached; skipping layout E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa2838320 – Eswar Jul 26 '18 at 10:33
  • Is your bottom navigation view visible now?? – yogesh lokhande Jul 26 '18 at 10:34
  • yes. its visible but when I tap on the icon below for which I am attempting this view. Nothing happens. No display comes. Only the contents of the activity_main.xml are shown. Nothing from this fragment. Please see the question I have edited to include the snippet of code where I am assigning the text and calling the function. The ProgressData() funtion is not displaying anything. – Eswar Jul 26 '18 at 10:40
  • share your methods – yogesh lokhande Jul 26 '18 at 10:46
  • Only the progressData function is giving problem of giving no display and I have shared that method. Moreover, the I have checked that the method is entered using Log.i(). When I put a log to print the text value, it says null. It says that text1 is null. – Eswar Jul 26 '18 at 10:49
  • "$text1?.text" returns null inspite of assigning a string as you can see in the method. – Eswar Jul 26 '18 at 10:55
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176796/discussion-between-eswar-and-yolo). – Eswar Jul 26 '18 at 11:15
  • What I want cannot be achieved because I was using fragments to display the data. I was using the adapter directly in the mainactivity. Now I have shifting to using fragments and figured out that it wont work if I have recyclerview in the activity_main.xml and want to replace it with scrollview. It might work if I disable the recyclerview and then use scrollview. Well, instead I shifted to a fragmented approach, now the problem is nearly solved. – Eswar Jul 26 '18 at 13:47
0

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.

Eswar
  • 1,201
  • 19
  • 45