Android program problem

This single activity program, when run on Eclipse AVD, is accepting values, but not printing the value when button is clicked. I want to ask the error, if any and the reason why the program is not giving the desired results.

package com.msi.manning.calc_ur_bmi;

import android.os.;
import android.view.
import android.widget.;
import android.content.*;
import java.text.NumberFormat;
import android.util.Log;

public class Calc_ur_BMI extends Activity
public void onCreate(Bundle savedInstanceState) {
final EditText weightfield=(EditText) findViewById(;
final EditText heightfield=(EditText) findViewById(;
final TextView bmifield=(TextView) findViewById(;
final Button button=(Button) findViewById(;
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
int num1=Integer.parseInt(weightfield.getText().toString());
float num2=Float.parseFloat(heightfield.getText().toString());

	    float ans=num1/num2*num2;
	    String S = null;
	    	S = "Oh ho!!! You are undernourished...";
	    	S = "You are appropriately nourished...";
	    	S = "Oh ho!!! You are overweight...";
	    String str = Float.toString(ans);
	} catch (Exception e)


@abhinavkaul95 : A better place to ask this would be

1 Like

Try creating another activity and printing on that.


In its .java file, you will have to create an object of Intent type and there get the string passed from MainActivity

while calculating answer, use the following…
brackets are essential.

float ans=num1/(num2*num2);

i think the problem is in float ans=num1/num2*num2; This is because the compiler evaluates according to bodmas. So, the desired result is not achieved. Apart from that when I checked it and it is giving the required text in the bmi textview. By printing if you want to print it to the logcat add Log.d(“debug”,str+S); after bmifield.setText(str+S);, or use System.out.println(str+s); to print to console. Also use for these kind of doubts.