I'm having problems with running the code on my device [duplicate]

徘徊边缘 提交于 2019-12-02 14:15:13

This is an issue:

eventListView = (ListView) inflater.inflate(R.layout.nav_events, container, false); 

You try to inflate listview but inflater returns you a LinearLayout a parent of all views. You need inflate the LinearLayout instead of listview and this is causes to cast exception.

You are trying to cast a layout on a listview

add this @id into your LinearLayout and inflate it in your Activity

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@id/layout";
tools:context="com.delaroystudiuos.alarmreminder.MainActivity">

and then call it like this

LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.layout, container, false);;

If you are trying to access your existing ListView item in the XML:

<ListView
android:id="@+id/list"
android:layout_below="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

You will need to instead use:

View view = inflater.inflate(R.layout.nav_events, container, false);    
eventListView = view.findViewById(R.id.list);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!