I have an simple app which updates number each time the button is clicked. This works perfectly on a normal Activity.
However, now I have made an popup window which I want to do the same inside, but when the button inside the popup window is clicked, I get the error:
android.content.res.Resources$NotFoundException: String resource ID #0x1
The error occurs when I try to update the TextView inside the popup window
Here is my simple code which again works perfectly on a normal Activity:
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
}
});
}}
Could someone help me please?
your method getReps()
is return integer value so you have to set text like below
repTextField.setText(String.valueFrom(the_workout_class.getReps()));
setsTextField.setText(String.valueFrom(the_workout_class.getReps()));