Results 1 to 4 of 4
- 11-30-2008, 08:28 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 8
- Rep Power
- 0
[SOLVED] operator / cannot to applied to java.lang.string,int
I have a label call scoreLabel and it shows the score the user will get. I want to convert the score to 100% so i try this
int sco = ((scoreLabel.getText()/16)*100); (16 is the total score)
But i get the error message saying operator / cannot to applied to java.lang.string,int
Can anyone help me with this?
- 11-30-2008, 11:20 AM #2
Read the API for JLabel and you'll see that getText() returns a String. Do you seriously expect to be able to divide a String by an int?
Keep track of the score in a variable of numeric type and use that for the calculation. And be aware of integer division so you use suitable variable types.
db
- 11-30-2008, 05:56 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 7
- Rep Power
- 0
Try
int sco = (Integer.valueOf(scoreLabel.getText())/16)*100;
Integer.valueOf(String)
Converts a string to a int
- 12-01-2008, 05:40 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Operator < cannot be applied to java.lang.Object, Object
By Albert in forum Advanced JavaReplies: 2Last Post: 11-26-2010, 02:12 AM -
Error Message: operator * cannot be applied to java.lang.String, int
By MICHAELABICK in forum Java AppletsReplies: 4Last Post: 11-27-2008, 06:09 AM -
String Object equality with == operator
By kumar080780 in forum New To JavaReplies: 4Last Post: 10-29-2008, 06:57 AM -
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
Error: cannot be applied to (java.lang.String)
By carl in forum New To JavaReplies: 1Last Post: 08-05-2007, 06:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks