0

The following piece of code:

if (e.getSource() == btnRe) {
  lblCounter.setText(count - count);
}

Throws the exception:

Exception: Incompatible tpyes: int cannot be converted to String "count - count"

I don't know how to change count into an integer that the method setText can read.

5
  • Use String.valueOf() Commented May 5, 2015 at 23:46
  • 1
    Use String#valueOf(count - count). But, on the other hand, count - count isn't 0? Or what are you trying to achieve? Commented May 5, 2015 at 23:46
  • Objective is to go from page to page and there's a counter in the middle and instead of going back all the way to 0 i wanted to make a button that you simply press and takes you automatically back to 0. Commented May 5, 2015 at 23:50
  • What do you want the text to be? "0"? Commented May 5, 2015 at 23:51
  • 1 so I would take the users current page, ex: "2234". There are arrows to go higher or lower in number but to make it easier there's a reset button that takes you back to zero, or one i haven't thought about that yet. Commented May 5, 2015 at 23:55

2 Answers 2

2

count - count is 0. You could use

lblCounter.setText(String.valueOf(count - count));

or just

lblCounter.setText("0");
Sign up to request clarification or add additional context in comments.

6 Comments

Yeah count - count = 0 i was gonna add ++ to it.
@Hooga And that would be "1".
This makes sense to set it to 0, but the overall project so that there's a counter, you press up and it goes up by one. After a point you get to a high number and you're done doing what you were gonna do. At this point youre at like page 600 and you wanna go back to 0 fast, so you press the reset button. lblCounter.setText("0"); just sets the text to zero but if you press up it goes to 601 i want to start back at 1. You get me?
@Hooga So String.valueOf(count % 600)?
value of int count is always changing so no. I have to subtract it by itself.
|
0

If you concatenate "" to the equation, java will know you're passing a string. If count is a String, this should do the trick.

    if (e.getSource() == btnRe) {

        lblCounter.setText("" + (Integer.parseInt(count) - Integer.parseInt(count)));
    }

Or, if it is an int, then use this.

    if (e.getSource() == btnRe) {

        lblCounter.setText("" + (count -count));
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.