ListView listView = (ListView) findViewById(R.id.listView);
findViewById(int) 回傳型別為 View(所有 UI 元件基類)。(ListView)。val listView = findViewById(R.id.listView) // 內建泛型推斷,無需轉型
若 ID 對應的 View 實際非 ListView(如 RecyclerView),執行時會拋 ClassCastException,請確認佈局 XML 中 android:id 正確。