Button btn = findViewById(R.id.xxx) 拋出 ClassCastException 或 NullPointerException。
**佈局 XML 中該 ID 對應的控件不是 Button**,可能是 TextView、ImageView、EditText 或自定義 View。
layout/xxx.xml)。android:id="@+id/xxx"。<Button>、<TextView> 等。TextView tv = findViewById(R.id.xxx);。findViewById,編譯期即可檢測類型不匹配。btn_ (Button)、tv_ (TextView)、et_ (EditText)、iv_ (ImageView),一眼識別類型。