Exception Inflating on Navigation View using RecyclerView, Fragment, and Activity with Kotlin












0















I have a program that will show some data to a fragment with a recyclerview and using json file for the data, i have tried this before and it's working properly, but when i use a bottom navigation, i meet this exception



java.lang.RuntimeException: Unable to start activity ComponentInfo{smktelkom.student.profil/smktelkom.student.profil.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
Caused by: java.lang.RuntimeException: Exception inflating smktelkom.student.profil:navigation/navigasinya line 41
at androidx.navigation.NavInflater.inflate(NavInflater.java:131)
at androidx.navigation.NavController.setGraph(NavController.java:419)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
Caused by: java.lang.IllegalArgumentException: smktelkom.student.profil.More.MoreFragment must be a subclass of class android.support.v4.app.Fragment
at androidx.navigation.NavDestination.parseClassFromName(NavDestination.java:111)
at androidx.navigation.fragment.FragmentNavigator$Destination.onInflate(FragmentNavigator.java:310)
at androidx.navigation.NavInflater.inflate(NavInflater.java:143)
at androidx.navigation.NavInflater.inflate(NavInflater.java:172)
at androidx.navigation.NavInflater.inflate(NavInflater.java:122)
at androidx.navigation.NavController.setGraph(NavController.java:419) 
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221) 
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659) 
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905) 
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715) 
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114) 
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374) 
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 


and this is my class file and navigation file in case you need it



package smktelkom.student.profil

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI.onNavDestinationSelected
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

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

// navigation_bottom.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)

navigation_bottom.setOnNavigationItemSelectedListener { item ->

onNavDestinationSelected(item, Navigation.findNavController(this, R.id.my_nav_host_fragment))

}


}
}


yeah this MainActivity is just this nothing else and the exception is linking to this class and i can't find the problem



this is the navigation file



<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/navigasinya"
app:startDestination="@id/navigation_profil">

<fragment
android:id="@+id/navigation_profil"
android:name="smktelkom.student.profil.Profil.ProfilFragment"
android:label="@string/title_profil"
tools:layout="@layout/fragment_profil">
<action
android:id="@+id/action_navigation_profil_to_main2Activity"
app:destination="@id/main2Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/navigation_hobi"
android:name="smktelkom.student.profil.Hobi.HobiFragment"
android:label="@string/title_hobi"
tools:layout="@layout/fragment_hobi">
<action
android:id="@+id/action_navigation_hobi_to_main3Activity"
app:destination="@id/main3Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="@+id/navigation_makanan"
android:name="smktelkom.student.profil.Makanan.MakananFragment"
android:label="@string/title_makanan"
tools:layout="@layout/fragment_makanan">
<action
android:id="@+id/action_navigation_makanan_to_main4Activity"
app:destination="@id/main4Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="@+id/navigation_more"
android:name="smktelkom.student.profil.More.MoreFragment"
android:label="@string/title_more"
tools:layout="@layout/fragment_more">
<action
android:id="@+id/action_navigation_more_to_main5Activity"
app:destination="@id/main5Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<activity
android:id="@+id/main2Activity"
android:name="smktelkom.student.profil.Main2Activity"
android:label="activity_main2"
tools:layout="@layout/activity_main2" />
<activity
android:id="@+id/main5Activity"
android:name="smktelkom.student.profil.Main5Activity"
android:label="activity_main5"
tools:layout="@layout/activity_main5" />
<activity
android:id="@+id/main3Activity"
android:name="smktelkom.student.profil.Main3Activity"
android:label="activity_main3"
tools:layout="@layout/activity_main3" />
<activity
android:id="@+id/main4Activity"
android:name="smktelkom.student.profil.Main4Activity"
android:label="activity_main4"
tools:layout="@layout/activity_main4" />
</navigation>


i have searching another problem that's same like me and their answer is to put the android:name below the id and i've already tried it and still nothing fixed



this is my fragment class



package smktelkom.student.profil.More
import android.annotation.TargetApi
import android.app.Fragment
import android.os.Build

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_more.*
import org.json.JSONArray
import org.json.JSONObject
import smktelkom.student.profil.News
import smktelkom.student.profil.NewsAdapter
import smktelkom.student.profil.R
import java.io.InputStream

class MoreFragment : Fragment() {

private val TAG : String = "News"
private lateinit var linearLayoutManager:LinearLayoutManager
private lateinit var mAdapter: NewsAdapter

@TargetApi(Build.VERSION_CODES.M)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_more, container, false)
recyclerView.layoutManager = LinearLayoutManager(context)
val jsonString:String = readJsonFromKotlinFile()
val newsList : ArrayList<News> = parseJsonStringToNewsList(jsonString)

mAdapter = NewsAdapter(newsList)
recyclerView.adapter = mAdapter
return view
}

private fun parseJsonStringToNewsList(jsonString: String): ArrayList<News> {
val newsList :ArrayList<News> = ArrayList<News>(0)
val newsArray = JSONArray(jsonString)
var i = 0
var numIterations = newsArray.length()
while(i < numIterations){
val newsObject:JSONObject = newsArray.getJSONObject(i)
val news = News()
news.news_title = newsObject.getString("news_title")
news.news_image_url = newsObject.getString("news_image_url")
news.news_source = newsObject.getString("news_source")
news.news_detail = newsObject.getString("news_detail")
news.news_url = newsObject.getString("news_url")
news.id = newsObject.getInt("id")
newsList.add(news)
i++
}
return newsList
}

private fun readJsonFromKotlinFile(): String {
var inputString = ""
try {
val inputStream:InputStream = activity.assets.open("news_data_file.json")
inputString = inputStream.bufferedReader().use{it.readText()}
Log.d(TAG,inputString)
} catch (e:Exception){
Log.d(TAG, e.toString())
}
return inputString
}


}


well, i think there's no problem with this class because the exception didn't mention it. Just in case you need it



and this is my fragment XML file



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorKuning"
tools:context="smktelkom.student.profil.More.MoreFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</android.support.constraint.ConstraintLayout>


I've tried to search this problem but there's no question like my problem is.
I hope everyone can help me.



Thank You










share|improve this question























  • Yudhistira Arda have a look here raywenderlich.com/…

    – Grendel
    Nov 19 '18 at 18:59











  • You've got the wrong Fragment class imported in MoreFragmentimport android.app.Fragment;. That should be import android.support.v4.app.Fragment;.

    – Mike M.
    Nov 20 '18 at 0:50











  • oh okay i'll try it

    – Bayu Yudhistira Arda Putra
    Nov 20 '18 at 3:15











  • i didn't see that

    – Bayu Yudhistira Arda Putra
    Nov 20 '18 at 3:15
















0















I have a program that will show some data to a fragment with a recyclerview and using json file for the data, i have tried this before and it's working properly, but when i use a bottom navigation, i meet this exception



java.lang.RuntimeException: Unable to start activity ComponentInfo{smktelkom.student.profil/smktelkom.student.profil.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
Caused by: java.lang.RuntimeException: Exception inflating smktelkom.student.profil:navigation/navigasinya line 41
at androidx.navigation.NavInflater.inflate(NavInflater.java:131)
at androidx.navigation.NavController.setGraph(NavController.java:419)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
Caused by: java.lang.IllegalArgumentException: smktelkom.student.profil.More.MoreFragment must be a subclass of class android.support.v4.app.Fragment
at androidx.navigation.NavDestination.parseClassFromName(NavDestination.java:111)
at androidx.navigation.fragment.FragmentNavigator$Destination.onInflate(FragmentNavigator.java:310)
at androidx.navigation.NavInflater.inflate(NavInflater.java:143)
at androidx.navigation.NavInflater.inflate(NavInflater.java:172)
at androidx.navigation.NavInflater.inflate(NavInflater.java:122)
at androidx.navigation.NavController.setGraph(NavController.java:419) 
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221) 
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659) 
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905) 
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715) 
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114) 
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374) 
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 


and this is my class file and navigation file in case you need it



package smktelkom.student.profil

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI.onNavDestinationSelected
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

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

// navigation_bottom.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)

navigation_bottom.setOnNavigationItemSelectedListener { item ->

onNavDestinationSelected(item, Navigation.findNavController(this, R.id.my_nav_host_fragment))

}


}
}


yeah this MainActivity is just this nothing else and the exception is linking to this class and i can't find the problem



this is the navigation file



<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/navigasinya"
app:startDestination="@id/navigation_profil">

<fragment
android:id="@+id/navigation_profil"
android:name="smktelkom.student.profil.Profil.ProfilFragment"
android:label="@string/title_profil"
tools:layout="@layout/fragment_profil">
<action
android:id="@+id/action_navigation_profil_to_main2Activity"
app:destination="@id/main2Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/navigation_hobi"
android:name="smktelkom.student.profil.Hobi.HobiFragment"
android:label="@string/title_hobi"
tools:layout="@layout/fragment_hobi">
<action
android:id="@+id/action_navigation_hobi_to_main3Activity"
app:destination="@id/main3Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="@+id/navigation_makanan"
android:name="smktelkom.student.profil.Makanan.MakananFragment"
android:label="@string/title_makanan"
tools:layout="@layout/fragment_makanan">
<action
android:id="@+id/action_navigation_makanan_to_main4Activity"
app:destination="@id/main4Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="@+id/navigation_more"
android:name="smktelkom.student.profil.More.MoreFragment"
android:label="@string/title_more"
tools:layout="@layout/fragment_more">
<action
android:id="@+id/action_navigation_more_to_main5Activity"
app:destination="@id/main5Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<activity
android:id="@+id/main2Activity"
android:name="smktelkom.student.profil.Main2Activity"
android:label="activity_main2"
tools:layout="@layout/activity_main2" />
<activity
android:id="@+id/main5Activity"
android:name="smktelkom.student.profil.Main5Activity"
android:label="activity_main5"
tools:layout="@layout/activity_main5" />
<activity
android:id="@+id/main3Activity"
android:name="smktelkom.student.profil.Main3Activity"
android:label="activity_main3"
tools:layout="@layout/activity_main3" />
<activity
android:id="@+id/main4Activity"
android:name="smktelkom.student.profil.Main4Activity"
android:label="activity_main4"
tools:layout="@layout/activity_main4" />
</navigation>


i have searching another problem that's same like me and their answer is to put the android:name below the id and i've already tried it and still nothing fixed



this is my fragment class



package smktelkom.student.profil.More
import android.annotation.TargetApi
import android.app.Fragment
import android.os.Build

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_more.*
import org.json.JSONArray
import org.json.JSONObject
import smktelkom.student.profil.News
import smktelkom.student.profil.NewsAdapter
import smktelkom.student.profil.R
import java.io.InputStream

class MoreFragment : Fragment() {

private val TAG : String = "News"
private lateinit var linearLayoutManager:LinearLayoutManager
private lateinit var mAdapter: NewsAdapter

@TargetApi(Build.VERSION_CODES.M)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_more, container, false)
recyclerView.layoutManager = LinearLayoutManager(context)
val jsonString:String = readJsonFromKotlinFile()
val newsList : ArrayList<News> = parseJsonStringToNewsList(jsonString)

mAdapter = NewsAdapter(newsList)
recyclerView.adapter = mAdapter
return view
}

private fun parseJsonStringToNewsList(jsonString: String): ArrayList<News> {
val newsList :ArrayList<News> = ArrayList<News>(0)
val newsArray = JSONArray(jsonString)
var i = 0
var numIterations = newsArray.length()
while(i < numIterations){
val newsObject:JSONObject = newsArray.getJSONObject(i)
val news = News()
news.news_title = newsObject.getString("news_title")
news.news_image_url = newsObject.getString("news_image_url")
news.news_source = newsObject.getString("news_source")
news.news_detail = newsObject.getString("news_detail")
news.news_url = newsObject.getString("news_url")
news.id = newsObject.getInt("id")
newsList.add(news)
i++
}
return newsList
}

private fun readJsonFromKotlinFile(): String {
var inputString = ""
try {
val inputStream:InputStream = activity.assets.open("news_data_file.json")
inputString = inputStream.bufferedReader().use{it.readText()}
Log.d(TAG,inputString)
} catch (e:Exception){
Log.d(TAG, e.toString())
}
return inputString
}


}


well, i think there's no problem with this class because the exception didn't mention it. Just in case you need it



and this is my fragment XML file



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorKuning"
tools:context="smktelkom.student.profil.More.MoreFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</android.support.constraint.ConstraintLayout>


I've tried to search this problem but there's no question like my problem is.
I hope everyone can help me.



Thank You










share|improve this question























  • Yudhistira Arda have a look here raywenderlich.com/…

    – Grendel
    Nov 19 '18 at 18:59











  • You've got the wrong Fragment class imported in MoreFragmentimport android.app.Fragment;. That should be import android.support.v4.app.Fragment;.

    – Mike M.
    Nov 20 '18 at 0:50











  • oh okay i'll try it

    – Bayu Yudhistira Arda Putra
    Nov 20 '18 at 3:15











  • i didn't see that

    – Bayu Yudhistira Arda Putra
    Nov 20 '18 at 3:15














0












0








0








I have a program that will show some data to a fragment with a recyclerview and using json file for the data, i have tried this before and it's working properly, but when i use a bottom navigation, i meet this exception



java.lang.RuntimeException: Unable to start activity ComponentInfo{smktelkom.student.profil/smktelkom.student.profil.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
Caused by: java.lang.RuntimeException: Exception inflating smktelkom.student.profil:navigation/navigasinya line 41
at androidx.navigation.NavInflater.inflate(NavInflater.java:131)
at androidx.navigation.NavController.setGraph(NavController.java:419)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
Caused by: java.lang.IllegalArgumentException: smktelkom.student.profil.More.MoreFragment must be a subclass of class android.support.v4.app.Fragment
at androidx.navigation.NavDestination.parseClassFromName(NavDestination.java:111)
at androidx.navigation.fragment.FragmentNavigator$Destination.onInflate(FragmentNavigator.java:310)
at androidx.navigation.NavInflater.inflate(NavInflater.java:143)
at androidx.navigation.NavInflater.inflate(NavInflater.java:172)
at androidx.navigation.NavInflater.inflate(NavInflater.java:122)
at androidx.navigation.NavController.setGraph(NavController.java:419) 
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221) 
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659) 
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905) 
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715) 
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114) 
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374) 
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 


and this is my class file and navigation file in case you need it



package smktelkom.student.profil

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI.onNavDestinationSelected
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

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

// navigation_bottom.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)

navigation_bottom.setOnNavigationItemSelectedListener { item ->

onNavDestinationSelected(item, Navigation.findNavController(this, R.id.my_nav_host_fragment))

}


}
}


yeah this MainActivity is just this nothing else and the exception is linking to this class and i can't find the problem



this is the navigation file



<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/navigasinya"
app:startDestination="@id/navigation_profil">

<fragment
android:id="@+id/navigation_profil"
android:name="smktelkom.student.profil.Profil.ProfilFragment"
android:label="@string/title_profil"
tools:layout="@layout/fragment_profil">
<action
android:id="@+id/action_navigation_profil_to_main2Activity"
app:destination="@id/main2Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/navigation_hobi"
android:name="smktelkom.student.profil.Hobi.HobiFragment"
android:label="@string/title_hobi"
tools:layout="@layout/fragment_hobi">
<action
android:id="@+id/action_navigation_hobi_to_main3Activity"
app:destination="@id/main3Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="@+id/navigation_makanan"
android:name="smktelkom.student.profil.Makanan.MakananFragment"
android:label="@string/title_makanan"
tools:layout="@layout/fragment_makanan">
<action
android:id="@+id/action_navigation_makanan_to_main4Activity"
app:destination="@id/main4Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="@+id/navigation_more"
android:name="smktelkom.student.profil.More.MoreFragment"
android:label="@string/title_more"
tools:layout="@layout/fragment_more">
<action
android:id="@+id/action_navigation_more_to_main5Activity"
app:destination="@id/main5Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<activity
android:id="@+id/main2Activity"
android:name="smktelkom.student.profil.Main2Activity"
android:label="activity_main2"
tools:layout="@layout/activity_main2" />
<activity
android:id="@+id/main5Activity"
android:name="smktelkom.student.profil.Main5Activity"
android:label="activity_main5"
tools:layout="@layout/activity_main5" />
<activity
android:id="@+id/main3Activity"
android:name="smktelkom.student.profil.Main3Activity"
android:label="activity_main3"
tools:layout="@layout/activity_main3" />
<activity
android:id="@+id/main4Activity"
android:name="smktelkom.student.profil.Main4Activity"
android:label="activity_main4"
tools:layout="@layout/activity_main4" />
</navigation>


i have searching another problem that's same like me and their answer is to put the android:name below the id and i've already tried it and still nothing fixed



this is my fragment class



package smktelkom.student.profil.More
import android.annotation.TargetApi
import android.app.Fragment
import android.os.Build

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_more.*
import org.json.JSONArray
import org.json.JSONObject
import smktelkom.student.profil.News
import smktelkom.student.profil.NewsAdapter
import smktelkom.student.profil.R
import java.io.InputStream

class MoreFragment : Fragment() {

private val TAG : String = "News"
private lateinit var linearLayoutManager:LinearLayoutManager
private lateinit var mAdapter: NewsAdapter

@TargetApi(Build.VERSION_CODES.M)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_more, container, false)
recyclerView.layoutManager = LinearLayoutManager(context)
val jsonString:String = readJsonFromKotlinFile()
val newsList : ArrayList<News> = parseJsonStringToNewsList(jsonString)

mAdapter = NewsAdapter(newsList)
recyclerView.adapter = mAdapter
return view
}

private fun parseJsonStringToNewsList(jsonString: String): ArrayList<News> {
val newsList :ArrayList<News> = ArrayList<News>(0)
val newsArray = JSONArray(jsonString)
var i = 0
var numIterations = newsArray.length()
while(i < numIterations){
val newsObject:JSONObject = newsArray.getJSONObject(i)
val news = News()
news.news_title = newsObject.getString("news_title")
news.news_image_url = newsObject.getString("news_image_url")
news.news_source = newsObject.getString("news_source")
news.news_detail = newsObject.getString("news_detail")
news.news_url = newsObject.getString("news_url")
news.id = newsObject.getInt("id")
newsList.add(news)
i++
}
return newsList
}

private fun readJsonFromKotlinFile(): String {
var inputString = ""
try {
val inputStream:InputStream = activity.assets.open("news_data_file.json")
inputString = inputStream.bufferedReader().use{it.readText()}
Log.d(TAG,inputString)
} catch (e:Exception){
Log.d(TAG, e.toString())
}
return inputString
}


}


well, i think there's no problem with this class because the exception didn't mention it. Just in case you need it



and this is my fragment XML file



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorKuning"
tools:context="smktelkom.student.profil.More.MoreFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</android.support.constraint.ConstraintLayout>


I've tried to search this problem but there's no question like my problem is.
I hope everyone can help me.



Thank You










share|improve this question














I have a program that will show some data to a fragment with a recyclerview and using json file for the data, i have tried this before and it's working properly, but when i use a bottom navigation, i meet this exception



java.lang.RuntimeException: Unable to start activity ComponentInfo{smktelkom.student.profil/smktelkom.student.profil.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
Caused by: java.lang.RuntimeException: Exception inflating smktelkom.student.profil:navigation/navigasinya line 41
at androidx.navigation.NavInflater.inflate(NavInflater.java:131)
at androidx.navigation.NavController.setGraph(NavController.java:419)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
Caused by: java.lang.IllegalArgumentException: smktelkom.student.profil.More.MoreFragment must be a subclass of class android.support.v4.app.Fragment
at androidx.navigation.NavDestination.parseClassFromName(NavDestination.java:111)
at androidx.navigation.fragment.FragmentNavigator$Destination.onInflate(FragmentNavigator.java:310)
at androidx.navigation.NavInflater.inflate(NavInflater.java:143)
at androidx.navigation.NavInflater.inflate(NavInflater.java:172)
at androidx.navigation.NavInflater.inflate(NavInflater.java:122)
at androidx.navigation.NavController.setGraph(NavController.java:419) 
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221) 
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659) 
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905) 
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715) 
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114) 
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374) 
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 


and this is my class file and navigation file in case you need it



package smktelkom.student.profil

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI.onNavDestinationSelected
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

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

// navigation_bottom.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)

navigation_bottom.setOnNavigationItemSelectedListener { item ->

onNavDestinationSelected(item, Navigation.findNavController(this, R.id.my_nav_host_fragment))

}


}
}


yeah this MainActivity is just this nothing else and the exception is linking to this class and i can't find the problem



this is the navigation file



<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/navigasinya"
app:startDestination="@id/navigation_profil">

<fragment
android:id="@+id/navigation_profil"
android:name="smktelkom.student.profil.Profil.ProfilFragment"
android:label="@string/title_profil"
tools:layout="@layout/fragment_profil">
<action
android:id="@+id/action_navigation_profil_to_main2Activity"
app:destination="@id/main2Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/navigation_hobi"
android:name="smktelkom.student.profil.Hobi.HobiFragment"
android:label="@string/title_hobi"
tools:layout="@layout/fragment_hobi">
<action
android:id="@+id/action_navigation_hobi_to_main3Activity"
app:destination="@id/main3Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="@+id/navigation_makanan"
android:name="smktelkom.student.profil.Makanan.MakananFragment"
android:label="@string/title_makanan"
tools:layout="@layout/fragment_makanan">
<action
android:id="@+id/action_navigation_makanan_to_main4Activity"
app:destination="@id/main4Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="@+id/navigation_more"
android:name="smktelkom.student.profil.More.MoreFragment"
android:label="@string/title_more"
tools:layout="@layout/fragment_more">
<action
android:id="@+id/action_navigation_more_to_main5Activity"
app:destination="@id/main5Activity"
app:enterAnim="@anim/nav_default_pop_enter_anim" />
</fragment>
<activity
android:id="@+id/main2Activity"
android:name="smktelkom.student.profil.Main2Activity"
android:label="activity_main2"
tools:layout="@layout/activity_main2" />
<activity
android:id="@+id/main5Activity"
android:name="smktelkom.student.profil.Main5Activity"
android:label="activity_main5"
tools:layout="@layout/activity_main5" />
<activity
android:id="@+id/main3Activity"
android:name="smktelkom.student.profil.Main3Activity"
android:label="activity_main3"
tools:layout="@layout/activity_main3" />
<activity
android:id="@+id/main4Activity"
android:name="smktelkom.student.profil.Main4Activity"
android:label="activity_main4"
tools:layout="@layout/activity_main4" />
</navigation>


i have searching another problem that's same like me and their answer is to put the android:name below the id and i've already tried it and still nothing fixed



this is my fragment class



package smktelkom.student.profil.More
import android.annotation.TargetApi
import android.app.Fragment
import android.os.Build

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_more.*
import org.json.JSONArray
import org.json.JSONObject
import smktelkom.student.profil.News
import smktelkom.student.profil.NewsAdapter
import smktelkom.student.profil.R
import java.io.InputStream

class MoreFragment : Fragment() {

private val TAG : String = "News"
private lateinit var linearLayoutManager:LinearLayoutManager
private lateinit var mAdapter: NewsAdapter

@TargetApi(Build.VERSION_CODES.M)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_more, container, false)
recyclerView.layoutManager = LinearLayoutManager(context)
val jsonString:String = readJsonFromKotlinFile()
val newsList : ArrayList<News> = parseJsonStringToNewsList(jsonString)

mAdapter = NewsAdapter(newsList)
recyclerView.adapter = mAdapter
return view
}

private fun parseJsonStringToNewsList(jsonString: String): ArrayList<News> {
val newsList :ArrayList<News> = ArrayList<News>(0)
val newsArray = JSONArray(jsonString)
var i = 0
var numIterations = newsArray.length()
while(i < numIterations){
val newsObject:JSONObject = newsArray.getJSONObject(i)
val news = News()
news.news_title = newsObject.getString("news_title")
news.news_image_url = newsObject.getString("news_image_url")
news.news_source = newsObject.getString("news_source")
news.news_detail = newsObject.getString("news_detail")
news.news_url = newsObject.getString("news_url")
news.id = newsObject.getInt("id")
newsList.add(news)
i++
}
return newsList
}

private fun readJsonFromKotlinFile(): String {
var inputString = ""
try {
val inputStream:InputStream = activity.assets.open("news_data_file.json")
inputString = inputStream.bufferedReader().use{it.readText()}
Log.d(TAG,inputString)
} catch (e:Exception){
Log.d(TAG, e.toString())
}
return inputString
}


}


well, i think there's no problem with this class because the exception didn't mention it. Just in case you need it



and this is my fragment XML file



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorKuning"
tools:context="smktelkom.student.profil.More.MoreFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</android.support.constraint.ConstraintLayout>


I've tried to search this problem but there's no question like my problem is.
I hope everyone can help me.



Thank You







android android-fragments kotlin android-navigation android-navigation-component






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 14:34









Bayu Yudhistira Arda PutraBayu Yudhistira Arda Putra

34




34













  • Yudhistira Arda have a look here raywenderlich.com/…

    – Grendel
    Nov 19 '18 at 18:59











  • You've got the wrong Fragment class imported in MoreFragmentimport android.app.Fragment;. That should be import android.support.v4.app.Fragment;.

    – Mike M.
    Nov 20 '18 at 0:50











  • oh okay i'll try it

    – Bayu Yudhistira Arda Putra
    Nov 20 '18 at 3:15











  • i didn't see that

    – Bayu Yudhistira Arda Putra
    Nov 20 '18 at 3:15



















  • Yudhistira Arda have a look here raywenderlich.com/…

    – Grendel
    Nov 19 '18 at 18:59











  • You've got the wrong Fragment class imported in MoreFragmentimport android.app.Fragment;. That should be import android.support.v4.app.Fragment;.

    – Mike M.
    Nov 20 '18 at 0:50











  • oh okay i'll try it

    – Bayu Yudhistira Arda Putra
    Nov 20 '18 at 3:15











  • i didn't see that

    – Bayu Yudhistira Arda Putra
    Nov 20 '18 at 3:15

















Yudhistira Arda have a look here raywenderlich.com/…

– Grendel
Nov 19 '18 at 18:59





Yudhistira Arda have a look here raywenderlich.com/…

– Grendel
Nov 19 '18 at 18:59













You've got the wrong Fragment class imported in MoreFragmentimport android.app.Fragment;. That should be import android.support.v4.app.Fragment;.

– Mike M.
Nov 20 '18 at 0:50





You've got the wrong Fragment class imported in MoreFragmentimport android.app.Fragment;. That should be import android.support.v4.app.Fragment;.

– Mike M.
Nov 20 '18 at 0:50













oh okay i'll try it

– Bayu Yudhistira Arda Putra
Nov 20 '18 at 3:15





oh okay i'll try it

– Bayu Yudhistira Arda Putra
Nov 20 '18 at 3:15













i didn't see that

– Bayu Yudhistira Arda Putra
Nov 20 '18 at 3:15





i didn't see that

– Bayu Yudhistira Arda Putra
Nov 20 '18 at 3:15












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376855%2fexception-inflating-on-navigation-view-using-recyclerview-fragment-and-activit%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376855%2fexception-inflating-on-navigation-view-using-recyclerview-fragment-and-activit%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()