Anyone can help me in this Java ME coding

Anyone help me please... Need Help....

/*

* bmi.java

*

* Created on June 17, 2007, 9:54 PM

*/

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

/**

*

* @author alpharif

* @version

*/

publicclass bmiextends MIDlet

{

private Display display;

private Command cmdExit;

private Command cmdCalculate;

private Command cmdOK;

private Form bmiInput;

private Form bmiOutput;

private TextField txtWeight;

private TextField txtHeight;

private StringItem bmiresult;

publicvoid startApp ()

{

display = Display.getDisplay (this);

cmdCalculate =new Command ("Calculate", Command.SCREEN, 1);

cmdExit =new Command ("Exit", Command.SCREEN, 1);

cmdOK =new Command ("OK", Command.SCREEN, 1);

bmiInput =new Form ("BMI Input");

txtWeight =new TextField ("Weight :", null, 5, TextField.DECIMAL);

bmiInput.addCommand (cmdCalculate);

bmiInput.addCommand (cmdExit);

bmiInput.setCommandListener (this);

bmiInput.append (txtWeight);

txtHeight =new TextField ("Height :", null, 5, TextField.DECIMAL);

bmiInput.append (txtHeight);

bmiOutput =new Form ("BMI Result");

bmiresult =new StringItem (null,null);

bmiOutput.append (bmiresult);

bmiInput.addCommand (cmdOK);

bmiInput.setCommandListener (this);

display.setCurrent (bmiInput);

}

publicvoid pauseApp ()

{

}

publicvoid destroyApp (boolean unconditional)

{

}

publicvoid commandAction(Command cmd, Displayable d)

{

String displayString =null;

if (cmd == cmdExit)

{

destroyApp (false);

notifyDestroyed();

}

elseif (cmd == cmdCalculate)

{

Double height;

Double weight;

Double calc;

weight = txtWeight;

height = txtHeight;

//displayString = calculateBMI (weight, height);

calc = height * weight;

displayString = calc.toString();

bmiresult.setText (displayString);

display.setCurrent (bmiOutput);

}

elseif (cmd == cmdOK)

{

txtWeight.setString (null);

txtHeight.setString (null);

display.setCurrent (bmiInput);

}

}

This is the error generated by netbeans 5.5.1

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\src\bmi.java:39: setCommandListener(javax.microedition.lcdui.CommandListener) in javax.microedition.lcdui.Displayable cannot be applied to (bmi)

bmiInput.setCommandListener (this);

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\src\bmi.java:48: setCommandListener(javax.microedition.lcdui.CommandListener) in javax.microedition.lcdui.Displayable cannot be applied to (bmi)

bmiInput.setCommandListener (this);

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\src\bmi.java:77: incompatible types

found: javax.microedition.lcdui.TextField

required: java.lang.Double

weight = txtWeight;

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\src\bmi.java:78: incompatible types

found: javax.microedition.lcdui.TextField

required: java.lang.Double

height = txtHeight;

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\src\bmi.java:82: operator * cannot be applied to java.lang.Double,java.lang.Double

calc = height * weight;

5 errors

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\nbproject\build-impl.xml:183: Compile failed; see the compiler error output for details.

BUILD FAILED (total time: 0 seconds)

[5853 byte] By [alpharifa] at [2007-11-27 7:56:16]
# 1
try to add "implements CommandListener" to be aspublic class bmi extends MIDlet implements CommandListener {-}thanks
primrosea at 2007-7-12 19:37:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

Thanks....

Now i get an error in this block of code:

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\src\bmi.java:83: incompatible types

found: double

required: java.lang.Double

dheight = Double.parseDouble (height);

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\src\bmi.java:84: incompatible types

found: double

required: java.lang.Double

dweight = Double.parseDouble (weight);

C:\Documents and Settings\alpharif\My Documents\My Projects\bmi\src\bmi.java:88: operator + cannot be applied to java.lang.Double,java.lang.Double

bmiOutput.append (new StringItem ("", dheight + dweight));

{

String height = txtHeight.getString ();

String weight = txtWeight.getString ();

//i want to convert the String type data : weight, height to Double typde data then display in StringItem

Double dheight, dweight;

dheight = Double.parseDouble (height);

dweight = Double.parseDouble (weight);

bmiresult.setText (displayString);

display.setCurrent (bmiOutput);

bmiOutput.append (new StringItem ("", dheight + dweight));

}

alpharifa at 2007-7-12 19:37:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
Welcome1. To convert from String to Double you can use this way:Double d = java.lang.Double.parseDouble(YourString)2. To convert from Double to String you can use this way:String Str = Str.valueOf(YourDouble)hopefuly I helped you
primrosea at 2007-7-12 19:37:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
i have try that coding... but still not working. incompatible type, found double, required java.lang.Double.
alpharifa at 2007-7-12 19:37:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
you should declare variables asdouble height;double weight;double calc;since you write "double" type with capetal litter now your application will work :)
primrosea at 2007-7-12 19:37:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6
also you should change this statment :displayString = calc.toString();To:displayString = displayString.valueOf(calc);
primrosea at 2007-7-12 19:37:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7

> i have try that coding... but still not working.

> incompatible type, found double, required

> java.lang.Double.

Only if u are deadly desperate to use Double objects in your program, use the Double contractor to retrieve the Double object from the double value.

e.g.dheight = new Double(Double.parseDouble (height));

Message was edited by:

find_suvro@SDN

find_suvro@SDNa at 2007-7-12 19:37:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8
thanks everyone... problem solve
alpharifa at 2007-7-12 19:37:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...