gpt4 book ai didi

java - Android 应用程序因 java.lang.StackOverflowError 而失败

转载 作者:行者123 更新时间:2023-11-30 02:17:17 25 4
gpt4 key购买 nike

我正在制作一个 android 程序,但由于 stackoverflow 错误而失败。我附上了我的代码。我正在使用安卓工作室。我相信它是由于 addTextChangedListener 而循环的,但我不明白为什么要这样做。

我的代码:

    rb1 = (RadioButton) findViewById(R.id.radioButtonCFM);
rb2 = (RadioButton) findViewById(R.id.radioButtonAC);

rb1.setOnClickListener(new RadioGroup.OnClickListener() {
public void onClick(View v) {
EditText e1 = (EditText) findViewById(R.id.editText);
String sUsername1 = e1.getText().toString();
if (TextUtils.isEmpty(sUsername1)) {
e1.setError("The item cannot be empty.");
return;
}

EditText e2 = (EditText) findViewById(R.id.editText2);
String sUsername2 = e2.getText().toString();
if (TextUtils.isEmpty(sUsername2)) {
e2.setError("The item cannot be empty.");
return;
}

EditText e3 = (EditText) findViewById(R.id.editText3);
String sUsername3 = e3.getText().toString();
if (TextUtils.isEmpty(sUsername3)) {
e3.setError("The item cannot be empty.");
return;
}

e1.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
}

public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}

public void onTextChanged(CharSequence s, int start,
int before, int count) {
EditText e1 = (EditText)findViewById(R.id.editText);
EditText e2 = (EditText)findViewById(R.id.editText2);
EditText e3 = (EditText)findViewById(R.id.editText3);
volume = Double.parseDouble(e1.getText().toString());
cfm = Double.parseDouble(e2.getText().toString());
ac = Double.parseDouble(e3.getText().toString());
TextView t1 = (TextView) findViewById(R.id.editText3);
volume = Double.parseDouble(e1.getText().toString());
cfm = Double.parseDouble(e2.getText().toString());
ac = cfm * 60 / volume;
t1.setText(Double.toString((double) Math.round(ac * 100000) / 100000));
}
});


e2.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
}

public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}

public void onTextChanged(CharSequence s, int start,
int before, int count) {
EditText e1 = (EditText)findViewById(R.id.editText);
EditText e2 = (EditText)findViewById(R.id.editText2);
EditText e3 = (EditText)findViewById(R.id.editText3);
volume = Double.parseDouble(e1.getText().toString());
cfm = Double.parseDouble(e2.getText().toString());
ac = Double.parseDouble(e3.getText().toString());
TextView t1 = (TextView) findViewById(R.id.editText3);
volume = Double.parseDouble(e1.getText().toString());
cfm = Double.parseDouble(e2.getText().toString());
ac = cfm * 60 / volume;
t1.setText(Double.toString((double) Math.round(ac * 100000) / 100000));
}
});

}});

rb2.setOnClickListener(new RadioGroup.OnClickListener() {
public void onClick(View v) {
EditText e1 = (EditText)findViewById(R.id.editText);
String sUsername1 = e1.getText().toString();
if(TextUtils.isEmpty(sUsername1)) {
e1.setError("The item cannot be empty.");
return;
}

EditText e2 = (EditText)findViewById(R.id.editText2);
String sUsername2 = e2.getText().toString();
if(TextUtils.isEmpty(sUsername2)) {
e2.setError("The item cannot be empty.");
return;
}

EditText e3 = (EditText)findViewById(R.id.editText3);
String sUsername3 = e3.getText().toString();
if(TextUtils.isEmpty(sUsername3)) {
e3.setError("The item cannot be empty.");
return;
}

e1.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
}

public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}

public void onTextChanged(CharSequence s, int start,
int before, int count) {
EditText e1 = (EditText)findViewById(R.id.editText);
EditText e2 = (EditText)findViewById(R.id.editText2);
EditText e3 = (EditText)findViewById(R.id.editText3);
volume = Double.parseDouble(e1.getText().toString());
cfm = Double.parseDouble(e2.getText().toString());
ac = Double.parseDouble(e3.getText().toString());

TextView t2 = (TextView)findViewById(R.id.editText2);
volume = Double.parseDouble(e1.getText().toString());
ac = Double.parseDouble(e3.getText().toString());
cfm = ac * volume / 60;
t2.setText(Double.toString((double) Math.round(cfm * 100000) / 100000));
}
});

e3.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
}

public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}

public void onTextChanged(CharSequence s, int start,
int before, int count) {
EditText e1 = (EditText)findViewById(R.id.editText);
EditText e2 = (EditText)findViewById(R.id.editText2);
EditText e3 = (EditText)findViewById(R.id.editText3);
volume = Double.parseDouble(e1.getText().toString());
cfm = Double.parseDouble(e2.getText().toString());
ac = Double.parseDouble(e3.getText().toString());

TextView t2 = (TextView)findViewById(R.id.editText2);
volume = Double.parseDouble(e1.getText().toString());
ac = Double.parseDouble(e3.getText().toString());
cfm = ac * volume / 60;
t2.setText(Double.toString((double) Math.round(cfm * 100000) / 100000));
}
});

}
});
}

最佳答案

正在监视 R.id.editText3 的输入的 TextWatcher 正在修改 R.id.editText2 的文本,后者又在修改 R。 id.editText3。通过它,您将无限次调用 onTextChanged(...)

关于java - Android 应用程序因 java.lang.StackOverflowError 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29088933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com