<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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:layout_width="match_parent" android:layout_height="match_parent" tools:context="ru.unturn.iksa.volountersevent.MainActivity"> <ListView android:id="@+id/listview" android:layout_width="344dp" android:layout_height="495dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> 

It is the ListView itself that calls it through ListView lv = (ListView) findViewByID (R.id.listview);

But the application crashes on startup and gives an error: https://pastebin.com/Y2JUmHsT

If the listview exists, how can it be null?

  • And why "became"? He most likely was. In order for XML markup to become an UI object, it needs to be flushed. Show the code where the markup is connected and where findViewByID is called. - Eugene Krivenja
  • Just leave it as an answer so I can mark it - K. Iksanov

1 answer 1

XML markup is just a UI description. In order to create UI controls on the basis of this description, the markup needs to be "in-flute".

Only then can you access UI objects, including using the findViewByID() method