Question

enter image description hereI am working on an android application called 'MyBMI'. I have created an item called 'About MyBMI' in the options menu which when clicked takes the user to another activity called 'AboutActivity'. But, when I click 'About MyBMI' in the options menu, my application crashes. Please help.

package com.mavenmaverick.mybmi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
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.Toast;



public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    final EditText entermass = (EditText) findViewById(R.id.entermass);
    final EditText enterheight = (EditText) findViewById(R.id.enterheight);
    entermass.requestFocus();

    Button BMI = (Button) findViewById(R.id.BMI);
    BMI.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if(TextUtils.isEmpty(entermass.getText().toString()) || TextUtils.isEmpty(enterheight.getText().toString()))
            {
                if(TextUtils.isEmpty(entermass.getText().toString()) || TextUtils.isEmpty(enterheight.getText().toString()))
                {
                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setIcon(R.drawable.ic_launcher);
                    builder.setTitle("Developer's Check");
                    builder.setMessage("Either Of The Text Fields Are Empty");

                    builder.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            dialog.cancel();

                        }

                    });

                    AlertDialog dialog = builder.create();
                    dialog.show();
                }
                    }
            else {
            double d = 0;
            double mass = Double.valueOf(entermass.getText().toString());           
            double height = Double.valueOf(enterheight.getText().toString());
            double heightF;
            heightF=height*0.3048;
            double bmi = mass/(heightF*heightF);
            d=bmi;
            int display = (int) bmi;

            Toast toast=Toast.makeText(getApplicationContext(), "Your BMI is " +display, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
            toast.show();   
                if(d<15.0)
                {
                    Toast.makeText(MainActivity.this,"You Are Very Severely Underweight", Toast.LENGTH_LONG).show();
                }   
                else if(d>=15.0 && d<=16.0){

                Toast.makeText(MainActivity.this,"You Are Severely Underweight", Toast.LENGTH_LONG).show();
                }
                else if(d>=15.0 && d<=16.0){

                Toast.makeText(MainActivity.this,"You Are Severely Underweight", Toast.LENGTH_LONG).show();
                }
            else if(d>=16.0 && d<=18.5){

                Toast.makeText(MainActivity.this,"You Are Severely Underweight", Toast.LENGTH_LONG).show();
                }
            else if(d>=18.5 && d<=25.0){

                Toast.makeText(MainActivity.this,"You Are Normal (healthy weight)", Toast.LENGTH_LONG).show();
                }
            else if(d>=25.0 && d<=30.0){

                Toast.makeText(MainActivity.this,"You Are Overweight", Toast.LENGTH_LONG).show();
                }
            else if(d>=30.0 && d<=35.0){

                Toast.makeText(MainActivity.this,"You Are Obese Class I (Moderately obese)", Toast.LENGTH_LONG).show();
                }
            else if(d>=35.0 && d<=40.0){

                Toast.makeText(MainActivity.this,"You Are Obese Class II (Severely obese)", Toast.LENGTH_LONG).show();
                }
            else if(d>40.0){

                Toast.makeText(MainActivity.this,"You Are Obese Class III (Very severely obese)", Toast.LENGTH_LONG).show();
                }
        }
        }   

    });

};
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    startActivity(new Intent(this, AboutActivity.class));
    return true;
}

};
Was it helpful?

Solution

Just a guess but have you added this about activity to the manifest?

Ok I think you're running out of bitmap space. You need to start recycling your bitmaps! There will be a bitmap method called .Recycle() which you can execute before changing activity! This should hopefully solve your problem!

Or you're loading a bitmap which is too large.. Hope this helps!

OTHER TIPS

The stacktrace says: Your activity has a RelativeLayout that has a background drawable that is too large and causes out-of-memory. Make the image smaller to make it consume less memory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top