I've been trying to show a PreferenceFragment inside of a dialogFragment but im not sure how...
I tried to put the preferencefragment in a layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/settings_fragment"
android:name="com.example.test.Fragments.SettingsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
then using it in the onCreateView
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreate(savedInstanceState);
val view = inflater!!.inflate(R.layout.dialog_preference, container, false)
return view
}
On my main activity im calling it like this:
override fun onClick(view: View) {
val id = view.id
when (id) {
R.id.btnSettings -> {
val dialog = SettingsDialog();
dialog.onCancel(object : DialogInterface {
override fun cancel() {
setTheme()
}
override fun dismiss() {
}
})
dialog.show(fragmentManager, null);
}
}
}
The first time i call it, it shows up but on the second try. It crashes..
Is there another way to show a PreferenceFragment in a dialog?
Could someone please let me know how to do that?
Thank you
This is the error message im getting
android.view.InflateException: Binary XML file line #5: 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 com.example.test.Dialog.SettingsDialog.onCreateView(SettingsDialog.kt:20)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.BackStackRecord.run(BackStackRecord.java:834)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #5: Duplicate id 0x7f0e0080, tag null, or parent id 0xffffffff with another fragment for com.example.test.Fragments.SettingsFragment
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2120)
at android.app.Activity.onCreateView(Activity.java:5328)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:34)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
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 com.example.test.Dialog.SettingsDialog.onCreateView(SettingsDialog.kt:20)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.BackStackRecord.run(BackStackRecord.java:834)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I found the answer in another post:
Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment
So when i added this to my onDestroyView
override fun onDestroyView() {
super.onDestroyView()
val frag = fragmentManager.findFragmentById(R.id.settings_fragment) as SettingsFragment?;
if (frag != null)
fragmentManager.beginTransaction().remove(frag).commit();
}
Everything works fine. If anyone can think of a better way to create a preference dialog please do let me know
Related
I have a problem in Fragment Transaction.
I want to change the fragment that is showing when the button is clicked
but when I try to click it, the application shuts down.
It keeps showing the error message,
Binary XML file line #6: Error inflating, and
Unable to instantiate fragment make sure class name exists, is public, and has an empty constructor that is public
I tried to add the newInstace() code but it is still not working
Below is the error code and my Activity, Fragment code. I have no idea what is wrong...
Help me please.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.illo, PID: 10709
android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.illo.WritePost1_Fragment: make sure class name exists, is public, and has an empty constructor that is public
at android.app.Fragment.instantiate(Fragment.java:538)
at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3547)
at android.app.FragmentController.onCreateView(FragmentController.java:102)
at android.app.Activity.onCreateView(Activity.java:6323)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.example.illo.WritePost_Step2_Fragment.onCreateView(WritePost_Step2_Fragment.kt:27)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.illo.WritePost1_Fragment" on path: DexPathList[[zip file "/data/app/com.example.illo-8XrFiUkhowzrFMYYQ7X5qw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.illo-8XrFiUkhowzrFMYYQ7X5qw==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Fragment.instantiate(Fragment.java:524)
at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3547)
at android.app.FragmentController.onCreateView(FragmentController.java:102)
at android.app.Activity.onCreateView(Activity.java:6323)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.example.illo.WritePost_Step2_Fragment.onCreateView(WritePost_Step2_Fragment.kt:27)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
class WritePostActivity : AppCompatActivity() {
// step 프래그먼트 가져오기
lateinit var step1Fragment : WritePost_Step1_Fragment
lateinit var step2Fragment : WritePost_Step2_Fragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_write_post)
// 툴바 설정
toolbarSetting()
// 처음에는 step1로 설정
ShowStep1()
// step 이동 버튼
btn_step1.setOnClickListener {
ShowStep1()
Toast.makeText(this#WritePostActivity, "Write Post Step1", Toast.LENGTH_SHORT).show()
}
btn_step2.setOnClickListener {
ShowStep2()
Toast.makeText(this#WritePostActivity, "Write Post Step2", Toast.LENGTH_SHORT).show()
}
// 글 쓰기 완료 버튼! (누르면 게시글이 등록됨)
btn_write_post_ok.setOnClickListener {
// *----서버/DB 필요----*
// 포스트로 등록
}
}
// 툴바 세팅
fun toolbarSetting() {
// 툴바로 세팅
setSupportActionBar(toolbar_write_post)
supportActionBar?.setDisplayShowCustomEnabled(true)
supportActionBar?.setDisplayShowTitleEnabled(false)
supportActionBar?.setHomeAsUpIndicator(R.drawable.icon_to_left); // 뒤로 가기 버튼 커스텀
supportActionBar?.setDisplayHomeAsUpEnabled(true) // 뒤로 가기 버튼 자동 생성
// 뒤로가기 버튼 설정
toolbar_write_post.setNavigationOnClickListener {
finish() // 액티비티 끝내기
overridePendingTransition(R.anim.no_animation, R.anim.slide_out_left) // 애니메이션
}
}
fun ShowStep1(){
step1Fragment = WritePost_Step1_Fragment()
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_write_post, step1Fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
}
fun ShowStep2(){
step2Fragment = WritePost_Step2_Fragment()
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_write_post, step2Fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
}
}
class WritePost_Step2_Fragment : Fragment() {
companion object {
fun newInstance(foo: Int): WritePost_Step2_Fragment {
val args= Bundle()
args.putInt("foo", foo)
val fragment= WritePost_Step2_Fragment()
fragment.arguments= args
return fragment
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view: View = inflater.inflate(R.layout.fragment_write_post_step2, container, false)
return view
}
// Activity의 OnCreate와 같은 역할을 하는 함수
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Log.d("life_cycle", "F onViewCreated")
super.onViewCreated(view, savedInstanceState)
}
}
you have error in you xml file (line no. 6 specifically), check your xml file first it is located in res/layout directory
I'm new to Kotlin and I created a constant array to use in spinner inside of fragment. When I try to run the code, the app crashes. I've tried to find a solution, but couldn't.
The really weird part, it worked perfectly yesterday when I worked on it, and today it's crashes.
this is my fragment:
class PersonalDetailsFragment : Fragment() {
private lateinit var listener: OnChangeFragmentListener
override fun onAttach(context: Context?) {
super.onAttach(context)
listener = getListenerOrThrowException(OnChangeFragmentListener::class.java)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val v = inflater.inflate(R.layout.fragment_personal_deatails, container, false)
v.spinnerAge.adapter = ArrayAdapter<Int>(context, android.R.layout.simple_list_item_1, LIST_AGE)
v.btnGoDetails.setOnClickListener { listener.changeFragment() }
return v
}
this is my Constant class:
class Constant {
companion object {
#JvmField val LIST_AGE = getAgeList()
private fun getAgeList(): Array<Int?> {
val array = arrayOfNulls<Int>(83)
for (i in array.indices){
var age = i + 17
array[i] = age
}
return array
}
}
Error Log:
2019-06-06 19:02:53.732 18331-18331/com.eldareini.kotlin.meet4match
E/tlin.meet4matc: No package ID 7f found for ID 0x7f0d0044.
2019-06-06 19:02:53.732 18331-18331/com.eldareini.kotlin.meet4match
D/AndroidRuntime: Shutting down VM
2019-06-06 19:02:53.736 18331-18331/com.eldareini.kotlin.meet4match E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.eldareini.kotlin.meet4match, PID: 18331
java.lang.ExceptionInInitializerError
at com.eldareini.kotlin.meet4match.signup.PersonalDetailsFragment.onCreateView(PersonalDetailsFragment.kt:57)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f0d0044
at android.content.res.Resources.getText(Resources.java:348)
at android.content.res.Resources.getString(Resources.java:441)
at com.eldareini.kotlin.meet4match.Constant.<clinit>(Constant.kt:69)
at com.eldareini.kotlin.meet4match.signup.PersonalDetailsFragment.onCreateView(PersonalDetailsFragment.kt:57)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I'm following MabBox tutorial at https://docs.mapbox.com/help/tutorials/android-navigation-sdk/ to make a simple navigation fragment that use the basics elements of it.
I already know that MapBox require to instantiate before inflating the View because I made it before on another Fragment to test it out where the fragment is part of a TabLayout component, however, in this one, there's only one Activity that loads the Fragment where I use the SDK and in this case it throws the same error that I fixed previously because I put it afterinflating the layout.
The errore that appears is this one:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.parkingclientapplication, PID: 14257
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.parkingclientapplication/com.example.parkingclientapplication.activities.MapDirectionActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.parkingclientapplication.activities.MapDirectionActivity.onCreate(MapDirectionActivity.kt:15)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException:
Using MapView requires calling Mapbox.getInstance(Context context, String accessToken) before inflating or creating the view. The access token parameter is required when using a Mapbox service.
Please see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one.
More information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.
at com.mapbox.mapboxsdk.Mapbox.validateMapbox(Mapbox.java:165)
at com.mapbox.mapboxsdk.Mapbox.getAccessToken(Mapbox.java:77)
at com.mapbox.mapboxsdk.storage.FileSource.<init>(FileSource.java:234)
at com.mapbox.mapboxsdk.storage.FileSource.getInstance(FileSource.java:68)
at com.mapbox.mapboxsdk.maps.renderer.MapRenderer.<init>(MapRenderer.java:34)
E/AndroidRuntime: at com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer.<init>(GLSurfaceViewMapRenderer.java:33)
at com.mapbox.mapboxsdk.maps.MapView$5.<init>(MapView.java:294)
at com.mapbox.mapboxsdk.maps.MapView.initialiseDrawingSurface(MapView.java:294)
at com.mapbox.mapboxsdk.maps.MapView.initialize(MapView.java:137)
at com.mapbox.mapboxsdk.maps.MapView.<init>(MapView.java:100)
... 25 more
The code for the Activity is:
class MapDirectionActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map_direction)
supportFragmentManager.inTransaction {
add(R.id.form_clientNavMenu, MapDirectionFragment())
}
//Logout action on custom toolbar layout
logout.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
}
}
The code for the onCreateView method of the Fragment is:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
Mapbox.getInstance(context!!, getString(R.string.access_token))
val view = inflater.inflate(R.layout.fragment_map_direction, container, false)
mapView = view.findViewById(R.id.mapView)
mapView.onCreate(savedInstanceState)
mapView.getMapAsync(this)
// Inflate the layout for this fragment
return view
}
I only wrote onCreateView method because I think the error could be in there instead on the rest of the code which is the same as in the link, but I could be wrong.
Set the method:
Mapbox.getInstance(this,getString(R.string.access_token));
Before the:
setContentView(R.layout.activity_map);
If you having this exception change code structure as follows.
i.e:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this,getString(R.string.access_token));
setContentView(R.layout.activity_map);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(
new Style.Builder().fromUrl(Style.MAPBOX_STREETS)
));
}
Thanks #Tobrun for the answer, the problem was not that I missed the accessToken but I mixed activity and fragment layout so the components in one of them should be in the other. However, looking for the accessToken made me realize about other possible ones.
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
my app couldn't start it crashes immediately after i installed it and i couldn't understand the error!
i have created two recylcerView for two fragments which are attached in the main activity xml file
Error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.invincible.fragfrag, PID: 14384
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.invincible.fragfrag/com.invincible.fragfrag.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.app.AlertController.RecycleListView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.app.AlertController.RecycleListView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
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:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.invincible.fragfrag.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path: DexPathList[[zip file "/data/app/com.invincible.fragfrag-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
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:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.invincible.fragfrag.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path:
MainActivity:
package com.invincible.fragfrag;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.findFragmentById(R.id.table_number_list) == null) {
TableNumber tableNumber=TableNumber.getTableNumber("number");
FragmentTransaction transaction =fragmentManager.beginTransaction();
transaction.add(R.id.table_number_list,tableNumber);
transaction.commit();
}
if (fragmentManager.findFragmentById(R.id.table_values) == null) {
TableValue tableValue=TableValue.getTableValue("value");
FragmentTransaction transaction =fragmentManager.beginTransaction();
transaction.add(R.id.table_values,tableValue);
transaction.commit();
}
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}
main xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.invincible.fragfrag.MainActivity">
<android.support.v7.app.AlertController.RecycleListView
android:id="#+id/recycler_view_one"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.v7.app.AlertController.RecycleListView>
<android.support.v7.app.AlertController.RecycleListView
android:layout_marginTop="5dp"
android:id="#+id/recycler_view_two"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.v7.app.AlertController.RecycleListView>
</LinearLayout>
plz help me out what's the error and how to handle two fragment with two recyclerview in one activity.
THANK YOU for your concern!
android.support.v7.widget.RecyclerView
use this code in your xml file to create a listview. Simple!
You probably want to use android.support.v7.widget.RecyclerView.
Additional info that you don't need to know
RecycleListView is a nested class of android.support.v7.app.AlertController. One would refer to it as android.support.v7.app.AlertController$RecycleListView (the dollar sign). This is why it crashed at this point.
RecycleListView extends ListView not RecyclerView. That's why it would later crash with ClassCastException when you would try to use it in Java.
RecycleListView is an internal class of appcompat-v7 not to be used in your project.
I made the same mistake. Try to replace
android.support.v7.app.AlertController.RecycleListView
with
android.support.v7.widget.RecyclerView