gpt4 book ai didi

java - 单击选项菜单中的项目时应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 21:11:18 26 4
gpt4 key购买 nike

enter image description here我正在开发一个名为“MyBMI”的安卓应用程序。我在选项菜单中创建了一个名为“About MyBMI”的项目,单击该项目会将用户带到另一个名为“AboutActivity”的 Activity 。但是,当我在选项菜单中单击“关于 MyBMI”时,我的应用程序崩溃了。请帮忙。

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;
}

};

最佳答案

只是猜测,但您是否已将有关 Activity 的信息添加到 list 中?

好的,我认为您的位图空间用完了。您需要开始回收您的位图!将有一个名为 .Recycle() 的位图方法,您可以在更改 Activity 之前执行它!这应该有望解决您的问题!

或者您加载的位图太大了。希望这对您有所帮助!

关于java - 单击选项菜单中的项目时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22735081/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com