package zyf.Ex10_UI;
import java.text.DecimalFormat;
import java.text.NumberFormat;
//import com.example.xiao.R;
//import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class BMIActivity extends Activity {
private static final String R = null;
private Bundle savedInstanceState;
//@Override
public void OnCreate(Bundle saveInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
Bundle bunde=this.getIntent().getExtras();
String sex=bunde.getString("sex");
Double height = bunde.getDouble("height");
String sexText="";
if (sex.equals("M")){
sexText="男性";
}
else
{
sexText="女性";
}
String weight=this.getWeight(sex,height);
TextView tv1=(TextView) findViewById(R.id.text1);
tv1.setText(""+sexText+"/n你的身高是"+height+"厘米\n你的标准体重是"+weight+"公斤");
}
private String format (double num){
NumberFormat formatter= new DecimalFormat("0.00");
String s = formatter.format(num);
return s;
}
private String getWeight(String sex , double height){
String weight="";
if (sex.equals("M")){
weight= format((height - 80)*0.7);}
else{
weight= format((height - 70)*0.6);
}
return weight;
}
}
layout cannot be resolved or is not a field
3 个解决方案
#1
从异常上看是 myLayout没有定义好
#2
再帮看下
mylayout.xml如下
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_x="50px"
android:layout_y="72px"
</TextView>
</AbsoluteLayout>
mylayout.xml如下
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_x="50px"
android:layout_y="72px"
</TextView>
</AbsoluteLayout>
#3
<TextView>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_x="50px"
android:layout_y="72px" >
</TextView>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_x="50px"
android:layout_y="72px" >
</TextView>
#1
从异常上看是 myLayout没有定义好
#2
再帮看下
mylayout.xml如下
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_x="50px"
android:layout_y="72px"
</TextView>
</AbsoluteLayout>
mylayout.xml如下
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_x="50px"
android:layout_y="72px"
</TextView>
</AbsoluteLayout>
#3
<TextView>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_x="50px"
android:layout_y="72px" >
</TextView>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_x="50px"
android:layout_y="72px" >
</TextView>