Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKayondo Martin
7,481 PointsHaving issues inflating a fragment list
With this line of code,
View view = (View)inflater.inflate(R.layout.fragment_list, container ,false);
I the following fragment extending class
public class ListFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = (View)inflater.inflate(R.layout.fragment_list, container ,false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list_recyclerView);
ListAdapter listAdapter = new ListAdapter();
recyclerView.setAdapter(listAdapter);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
return view;
}
}
I get the following error message.
07-06 01:16:35.110 990-990/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.kayondomartin.smellslikebacon, PID: 990 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kayondomartin.smellslikebacon/com.example.kayondomartin.smellslikebacon.MainActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.support.v7.app.AlertController.RecycleListView 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:6540) 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 android.support.v7.app.AlertController.RecycleListView Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.app.AlertController.RecycleListView Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path: DexPathList[[zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/base.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.kayondomartin.smellslikebacon-Bnh_Ui9bXui-Sjfxp_Y7HA==/lib/x86, /system/lib, /system/vendor/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.view.LayoutInflater.createView(LayoutInflater.java:609) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:793) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:426) at com.example.kayondomartin.smellslikebacon.ListFragment.onCreateView(ListFragment.java:16) at android.app.Fragment.performCreateView(Fragment.java:2611) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1276) at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2413) 07-06 01:16:35.114 990-990/? E/AndroidRuntime: at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2192) at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2146) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2047) at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3040) at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2987) at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:178) at android.app.Activity.performCreateCommon(Activity.java:6974) at android.app.Activity.performCreate(Activity.java:6982) 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:6540) 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)
Ben Deitch
Treehouse TeacherThat all seems fine to me. Though maybe there's something wrong with the layout file; could you post that as well?
Kayondo Martin
7,481 Points<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/item_image"
android:layout_width="0dp"
android:scaleType="fitCenter"
android:layout_margin="8dp"
android:layout_weight="1"
android:layout_height="50dp"
app:srcCompat="@drawable/bagels"/>
<TextView
android:id="@+id/item_text"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_margin="12dp"
android:textSize="24sp"
android:layout_height="wrap_content"
android:text="TextView"/>
</LinearLayout>
this is my layout
2 Answers
Kayondo Martin
7,481 Pointsfound it, it was in the fragment_list xml file, forgot to use widget.RecyclerView
Mahmoud Amin
Courses Plus Student 6,269 Points1-Check the id you are putting as an argument for findViewById() 2-Where is the list data you are passing to the adapter to represent??
Kayondo Martin
7,481 PointsKayondo Martin
7,481 Points(@BenDeitch)