程序出现错误,调试不出,待改!!!!
附上现在代码,忘各位大大给予帮助
主活动
package com.example.second;
import com.example.secondandoidtwo.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class MainActivity extends Activity {
Button button;
RadioGroup radiogroup;
RadioButton radiobutton1,radiobutton2;
EditText edittext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radiogroup = (RadioGroup)findViewById(R.id.radoigroup);
radiobutton1=(RadioButton)findViewById(R.id.radioButton1);
radiobutton2=(RadioButton)findViewById(R.id.radioButton2);
button=(Button)findViewById(R.id.button1);
edittext=(EditText)findViewById(R.id.edinput);
button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String Input = edittext.getText().toString();
int b = Integer.parseInt(Input);
final double weight1 = (b-80)*0.7;
final double weight2 = (b-70)*0.6;
final Intent intent = new Intent(MainActivity.this,ShowActivity.class);
radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if(checkedId==radiobutton1.getId())
{
intent.putExtra("weight", "你的标准体重是"+weight1+"千克\n");
intent.putExtra("xingbie", "你是一名"+checkedId+"\n");
}
if(checkedId==radiobutton2.getId())
{
intent.putExtra("weight", "你的标准体重是"+weight2+"千克\n");
intent.putExtra("xingbie", "你是一名"+checkedId+"\n");
}
}
});
intent.putExtra("height","你的身高是"+Input+"厘米\n");
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
show活动
package com.example.second;
import com.example.secondandoidtwo.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class ShowActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
Intent intent= getIntent();
TextView textview = (TextView) findViewById(R.id.baogao) ;
String sex = intent.getStringExtra("xingbie");
String height = intent.getStringExtra("height");
String weight = intent.getStringExtra("weight");
textview.setText(sex + height + weight);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.show, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
主活动布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.second.MainActivity"
android:background="@drawable/bg">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="33dp"
android:text="@string/shen_gao"
android:textColor="#000000"/>
<EditText
android:id="@+id/edinput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_alignTop="@+id/textView3"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:background="@android:color/primary_text_dark"
android:hint="@string/input_height"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="31dp"
android:text="@string/xing_bie"
android:textColor="#000000" />
<RadioGroup
android:id="@+id/radoigroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/textView2"
android:layout_toRightOf="@id/textView1">
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/xb_nan" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/xb_nv" />
</RadioGroup>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/edinput"
android:layout_marginTop="23dp"
android:text="@string/jisuan" />
</RelativeLayout>
show活动布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.second.ShowActivity" >
<TextView
android:id="@+id/baogao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
附上log出错打印