• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps No applicable method to float

DevHenrik

Lurker
How do I solve this?
It sais: "There is no applicable method to float" , maybe not right spelled...
My code is like this and the error shows on last line at "calc"

The float numbers is connected to EditText widgets.

public void CalcButton(View button) {
float no1 = Float.parseFloat(fp.getText().toString());
float no2 = Float.parseFloat(fC.getText().toString());
float no3 = Float.parseFloat(drive.getText().toString());
float calc = (no1*no2)*no3;
totalcost.setText(calc);
}
 
Because there is a setText(int resid) method so it won't show any error, however I don't think it would do the expected behavior you want since from what I see you want to show the number result of a calculation? While the resid provides an int which represents the id of a string in your xml.

Try look in the original Android documentation for possible setText methods:
http://developer.android.com/reference/android/widget/TextView.html

You must either use a CharSequence or the setText (char[] text, int start, int len) option, and convert your float to a string first.
 
I got it working... by this code public void CalcButton(View button) {

String n1 = fp.getText().toString();
float no1 = Float.parseFloat(n1);

String n2 = fC.getText().toString();
float no2 = Float.parseFloat(n2);

String n3 = drive.getText().toString();
float no3 = Float.parseFloat(n3);


float calc = no1*(no2*no3);

String sum = Float.toString(calc);
totalcost.setText(sum);


}
 
Back
Top Bottom