2 回答

TA貢獻1886條經驗 獲得超2個贊
正如我注意到的,您的 Dialog 窗口中有leagueIdtextView。因此,請確保您的布局文件tvLeagueId中有一個帶有 id的 textView activity_bowlers_dialog。
然后在你的openDialog函數中使用view.findViewById引用 textview
public void openDialog(final boolean shouldUpdate, final Bowler bowler, final int position) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
View view = View.inflate(this, R.layout.activity_bowlers_dialog, null);
leagueId = view.findViewById(R.id.tvLeagueId); // <-- Add this line
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(BowlerActivity.this);
alertDialogBuilderUserInput.setView(view);
leagueId.setText(savedLeagueId);
final EditText inputBowler = view.findViewById(R.id.etBowlerName);
// rest of the code

TA貢獻1828條經驗 獲得超13個贊
它與如何從返回 null 的 findViewById 中獲取 TextView 的意圖沒有任何問題。
java.lang.NullPointerException:嘗試在* 空對象引用上調用虛擬方法“void android.widget.TextView.setText(java.lang.CharSequence)” *
添加回答
舉報