有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在Android上更新弹出窗口上的textview时出现java错误

我有一个简单的应用程序,每次点击按钮都会更新数字。这在正常活动中非常有效

然而,现在我制作了一个弹出窗口,我想在里面做同样的事情,但是当点击弹出窗口内的按钮时,我得到了错误:

安卓.content.res.Resources$NotFoundException: String resource ID #0x1

当我试图在弹出窗口内更新TextView时,会发生错误

下面是我的简单代码,它同样适用于正常活动:

public class PopActivity extends Activity {
private WorkOutClass the_workout_class = new WorkOutClass();

private TextView repTextField, setsTextField;
private Button den_knappen;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pop);

    repTextField = (TextView) findViewById(R.id.repetitionID);
    setsTextField = (TextView) findViewById(R.id.setsID);
    den_knappen = (Button) findViewById(R.id.buttonID);

    repTextField.setText("" + the_workout_class.getReps());
    setsTextField.setText(""+ the_workout_class.getSets());



    DisplayMetrics dm = new DisplayMetrics();

    getWindowManager().getDefaultDisplay().getMetrics(dm);

    int width = dm.widthPixels;
    int height = dm.heightPixels;

    getWindow().setLayout((int)(width*.8), (int)(height*.7));

    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.gravity = Gravity.CENTER;
    params.x = 0;
    params.y = 20;

    getWindow().setAttributes(params);

    den_knappen.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            the_workout_class.increaseReps();

            repTextField.setText(the_workout_class.getReps());  // Normally this works perfectly, but here i get ERROR
            setsTextField.setText(the_workout_class.getReps()); // Normally this works perfectly, but here i get ERROR

        }
    });



}}

谁能帮帮我吗


共 (1) 个答案

  1. # 1 楼答案

    你的方法getReps()是返回整数值,所以你必须像下面这样设置文本

     repTextField.setText(String.valueFrom(the_workout_class.getReps()));  
     setsTextField.setText(String.valueFrom(the_workout_class.getReps()));