errorString cannot be resolved or is not a field
代码如下,路过的帮看看,谢谢。
package zfy.Ex11_UI_A;
import zfy.Ex11_UI_A.BMIActivity;
import zyf.Ex11_UI_A.R;
import android.os.Bundle;
import android.app.Activity;
//import android.view.Menu;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
public class Ex11_UI_A extends Activity {
protected int my_requestcode=1550;
private EditText edit_height;
private RadioButton radiobutton_Man,radiobutton_Woman;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ok=(Button)findViewById(R.id._button_OK);
edit_height = (EditText)findViewById(R.id.height_Edit);
radiobutton_Man=(RadioButton)findViewById(R.id.Sex_Man);
radiobutton_Woman=(RadioButton)findViewById(R.id.Sex_Woman);
ok.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
try{
double height=Double.parseDouble(edit_height.getText().toString());
String sex="";
if (radiobutton_Man.isChecked()){
sex="M";}
else{
sex="F" ;
}
Intent intent=new Intent();
intent.setClass(Ex11_UI_A.this,BMIActivity.class);
Bundle bundle=new Bundle();
bundle.putDouble("height", height);
bundle.putString("sex", sex);
intent.putExtras(bundle);
startActivityForResult(intent,my_requestcode);}
catch(Exception e){
//以下要补回
Toast.makeText(Ex11_UI_A.this,R.string.errorString,Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
switch(resultCode){
case RESULT_OK:
Bundle bunde=data.getExtras();
String sex=bunde.getString("sex");
double height=bunde.getDouble("height");
if (sex.equals("M")){
radiobutton_Man.setChecked(true);
}else{
radiobutton_Woman.setChecked(true);
}
break;
default:
break;
}
}
}
------解决方案--------------------
你startActivityForResult使用的intent,和你在onActivityResult中intent不是同一个哈,请仔细学习下startActivityForResult的使用和onActivityResult什么时候被调用哈。