致命错误异常主要

时间:2014-10-31 14:35:58

标签: java android android-activity fatal-error

我的项目有问题。我调试它,我发现当应用程序想要从BMIcalculater .java活动转到BmiResult.java活动时发生致命错误但我无法找到如何解决它。我的代码中没有任何问题。任何人都可以帮助我吗?

错误:

10-31 14:28:10.685: E/AndroidRuntime(1085): FATAL EXCEPTION: main
10-31 14:28:10.685: E/AndroidRuntime(1085): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dietp/com.example.dietp.BmiResult}: android.content.res.Resources$NotFoundException: String resource ID #0x12
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.os.Looper.loop(Looper.java:137)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at java.lang.reflect.Method.invokeNative(Native Method)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at java.lang.reflect.Method.invoke(Method.java:511)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at dalvik.system.NativeStart.main(Native Method)
10-31 14:28:10.685: E/AndroidRuntime(1085): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x12
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.content.res.Resources.getText(Resources.java:229)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.widget.TextView.setText(TextView.java:3620)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at com.example.dietp.BmiResult.onCreate(BmiResult.java:41)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.app.Activity.performCreate(Activity.java:5008)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-31 14:28:10.685: E/AndroidRuntime(1085):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

这是BMIcalculater代码的一部分

public class BmiCalculaterPage extends ActionBarActivity  {
String gender;
RadioButton maleRadioButton;
RadioButton femaleRadioButton;
Button saveinformation ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bmi_calculater_page);
    maleRadioButton=(RadioButton) findViewById(R.id.maleselected);
    femaleRadioButton=(RadioButton) findViewById(R.id.femaleselected);

    final RadioGroup genderselected=(RadioGroup) findViewById(R.id.selectgender);
    genderselected.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup arg0, int selectedId) {
            // TODO Auto-generated method stub
            selectedId=genderselected.getCheckedRadioButtonId();
            RadioButton genderchoosed = (RadioButton) findViewById(selectedId);
            gender= genderchoosed.getText().toString();

        }
    });
    saveinformation = (Button) findViewById(R.id.saveinformation);
    saveinformation.setOnClickListener(new View.OnClickListener() {

        EditText heighttext=(EditText) findViewById(R.id.heighttext);
        EditText weighttext=(EditText) findViewById(R.id.weighttext);
        EditText agetext=(EditText) findViewById(R.id.agetext);
        Spinner activitytext=(Spinner) findViewById(R.id.chooseactivity);
        Button saveinformation=(Button) findViewById(R.id.saveinformation);

        String pa=activitytext.getSelectedItem().toString();


        @Override
        public void onClick(View v) {
            if(maleRadioButton.isChecked()) {
                gender= maleRadioButton.getText().toString();
            } else {
                gender = femaleRadioButton.getText().toString();
            }

            int weight = (int) Float.parseFloat(weighttext.getText().toString());
            float height =  Float.parseFloat(heighttext.getText().toString());
            int age = (int) Float.parseFloat(agetext.getText().toString());
            String pa = activitytext.getSelectedItem().toString();

            //  CALCULATING PART ===============================================================

            int Bmivalue = calculateBMI(weight, height);
            String bmiInterpretation = interpretBMI(Bmivalue);
            double idealweight =idealweight(weight, height, gender, pa, age);
            double dailycalories=dailycalories(weight,height,gender,pa,age);

            //INSERT TO DATABASE ===============================================================

            User user=new User();
            user.setHeight(height);
            user.setWeight(weight);
            user.setAge(age);
            user.setGender(gender);
            user.setPa(pa);
            user.setBmivalue(Bmivalue);
            user.setBmiInterpretation(bmiInterpretation);
            user.setIdealweight(idealweight);
            user.setDailycalories(dailycalories);

            com.example.dietp.database.DatabaseAdapter dbAdapter = new com.example.dietp.database.DatabaseAdapter(BmiCalculaterPage.this);
            dbAdapter.insertUser(user);

            Intent intent= new Intent(getApplicationContext(),BmiResult.class);
            intent.putExtra("Bmivalue", Bmivalue);
            intent.putExtra("bmiInterpretation", bmiInterpretation);
            intent.putExtra("idealweight", idealweight);
            intent.putExtra("dailycalories", dailycalories);
            startActivity(intent);



        }
    });

}
}

这是bmi calculater(我的第二页)的结果

public class BmiResult extends ActionBarActivity {
int Bmivalue;
String bmiInterpretation;
String idealweight;
String dailycalories;
TextView showBmivalueresult;
TextView showIdealweightresult;
TextView showDailycaloryresult;
TextView showBmiinterpretationresult;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bmi_result);

    Bmivalue=getIntent().getExtras().getInt("Bmivalue");
    bmiInterpretation=getIntent().getExtras().getString("bmiInterpretation");
    idealweight=getIntent().getExtras().getString("idealweight");
    dailycalories=getIntent().getExtras().getString("dailycalories");

    showBmivalueresult=(TextView) findViewById(R.id.showBmivalueresult);
    showIdealweightresult=(TextView) findViewById(R.id.showIdealweightresult);
    showDailycaloryresult=(TextView) findViewById(R.id.showDailycaloryresult);
    showBmiinterpretationresult=(TextView) findViewById(R.id.showBmiinterpretationresult);

    showBmivalueresult.setText(Bmivalue);
    showBmiinterpretationresult.setText(bmiInterpretation);     
    showDailycaloryresult.setText(dailycalories);
    showIdealweightresult.setText(idealweight);


}
}

0 个答案:

没有答案