所以我是新來的Android編程,所以我很抱歉如果這是一個初學者的錯誤,但我編程我的按鈕來添加一個用戶到一個數組列表中給出的名稱對話框。當我運行它時,除了執行users.add(新用戶(name))時,所有東西都可以工作。 (它返回一個空pointerI'm不清楚,爲什麼是這種情況。任何幫助將不勝感激。這是我的代碼。Android輸入對話框的Onclick不起作用
addPersonButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final EditText input = new EditText(mainActivity);
new AlertDialog.Builder(mainActivity)
.setTitle("New User")
.setMessage("What is the new user's name?")
.setView(input)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final String name = input.getText().toString();
users.add(new User(name));
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}).show();
}
});
顯示您的logcat的...... –
其中HVú初始化用戶? –