android - Android 应用 在Android手机上崩溃,但不在 Android 模拟器 ( Android Studio ) 上

  显示原文与译文双语对照的内容
0 0

我刚刚发布了一个应用程序,我昨天测试过。 应用程序完美地在 Android Studio ( 当然除了速度慢)的仿真程序上工作,但是应用程序在应用( 其中一个主要特征) 中执行特定部分。

我今天早上又在模拟器上测试了一下,仍然在我的电脑上工作。

我检查了在这个崩溃( 参考下面) 中发生的代码,但看起来不能找到任何内容:

CalculateActivity


public class CalculateActivity extends ActionBarActivity {

 TextView txtBewareTurnoverTime;

 EditText txtPoolSize;
 EditText txtTurnoverTime;
 EditText txtTurnoverRate;

 Button btnCalculate;

 ImageButton imgBtnTurnoverTime, imgBtnTurnoverRate;

 Animation shakeAni;

 RelativeLayout layoutPoolSize, layoutTurnoverTime, layoutTurnoverRate;
 LinearLayout layoutInfoTurnoverRate;
 LinearLayout layoutInfoTurnoverTime;

 boolean infoTurnoverRate = false;
 boolean infoTurnoverTime = false;

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

 FindAllById();
 SetListeners();
 }

//Finds all views by their ID and applies them to the variables
 private void FindAllById() {
 txtPoolSize = (EditText) findViewById(R.id.txtPoolSizeEdit);
 txtTurnoverTime = (EditText) findViewById(R.id.txtTurnoverTimeEdit);
 txtTurnoverRate = (EditText) findViewById(R.id.txtTurnoverRateEdit);
 txtBewareTurnoverTime = (TextView) findViewById(R.id.txtInfoTurnoverTime);
 layoutPoolSize = (RelativeLayout) findViewById(R.id.layoutPoolSize);
 layoutTurnoverTime = (RelativeLayout) findViewById(R.id.layoutTurnoverTime);
 layoutTurnoverRate = (RelativeLayout) findViewById(R.id.layoutTurnoverRate);
 imgBtnTurnoverRate = (ImageButton) findViewById(R.id.imgBtnTurnoverRate);
 imgBtnTurnoverTime = (ImageButton) findViewById(R.id.imgBtnTurnoverTime);
 layoutInfoTurnoverRate = (LinearLayout) findViewById(R.id.layoutInfoTurnoverRate);
 layoutInfoTurnoverRate.setVisibility(View.GONE);
 layoutInfoTurnoverTime = (LinearLayout) findViewById(R.id.layoutInfoTurnoverTime);
 layoutInfoTurnoverTime.setVisibility(View.GONE);
 }

//Set the listeners on the various components
 private void SetListeners(){
 btnCalculate = (Button) findViewById(R.id.calculateBtnCalcView);
 btnCalculate.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 ShakeAnimation();
 }
 });

 imgBtnTurnoverTime.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 if(!infoTurnoverTime){layoutInfoTurnoverTime.setVisibility(View.VISIBLE); infoTurnoverTime = true;}
 else{layoutInfoTurnoverTime.setVisibility(View.GONE); infoTurnoverTime = false;}
 }
 });

 imgBtnTurnoverRate.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 if(!infoTurnoverRate){layoutInfoTurnoverRate.setVisibility(View.VISIBLE); infoTurnoverRate = true;}
 else{layoutInfoTurnoverRate.setVisibility(View.GONE); infoTurnoverRate = false;}
 }
 });
 }

//Plays the animation for the correct relative layouts, if any
 private void ShakeAnimation(){

 shakeAni = AnimationUtils.loadAnimation(CalculateActivity.this, R.anim.shake);
 int switchInt = new AnimationHelper().CalculateAnimationInt(txtPoolSize.getText().toString(), txtTurnoverTime.getText().toString(), txtTurnoverRate.getText().toString());

 switch(switchInt){
 case 1: layoutPoolSize.startAnimation(shakeAni);
 layoutTurnoverTime.startAnimation(shakeAni);
 layoutTurnoverRate.startAnimation(shakeAni);
 break;
 case 2: layoutPoolSize.startAnimation(shakeAni);
 layoutTurnoverTime.startAnimation(shakeAni);
 break;
 case 3: layoutPoolSize.startAnimation(shakeAni);
 layoutTurnoverRate.startAnimation(shakeAni);
 break;
 case 4: layoutTurnoverTime.startAnimation(shakeAni);
 layoutTurnoverRate.startAnimation(shakeAni);
 break;
 case 5: layoutPoolSize.startAnimation(shakeAni);
 break;
 case 6: layoutTurnoverTime.startAnimation(shakeAni);
 break;
 case 7: layoutTurnoverRate.startAnimation(shakeAni);
 break;
 case 8: StartResultActivity();
 break;
 }
 }

//Start the ResultActivity with the given variables
 private void StartResultActivity(){
 Intent i = new Intent().setClass(CalculateActivity.this, ResultActivity.class);
 i.putExtra("poolSize", txtPoolSize.getText().toString());
 i.putExtra("turnoverTime", txtTurnoverTime.getText().toString());
 i.putExtra("turnoverRate", txtTurnoverRate.getText().toString());
 startActivity(i);
 }
}

ResultActivity


public class ResultActivity extends ActionBarActivity {

 TextView resultPumpRequirement;
 TextView resultFilterAreaRequirement;
 TextView resultMinimumDiameterFilter;

 Button btnFilters;
 Button btnPumps;

 String poolSize;
 String turnoverTime;
 String turnoverRate;

 int pumpRequirement;
 double filterAreaRequiment;
 int minimumDiameterFilter;

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


 Intent intent = getIntent();

 if(intent!= null) {
 poolSize = intent.getStringExtra("poolSize");
 turnoverTime = intent.getStringExtra("turnoverTime");
 turnoverRate = intent.getStringExtra("turnoverRate");

 Calculate();
 SetText();
 SetListeners();
 }
 }

//Set the listeners on the various components
 private void SetListeners() {
 btnFilters = (Button) findViewById(R.id.btnFilters);
 btnFilters.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(new URLHelper().CreateFilterURL(minimumDiameterFilter))));
 }
 });

 btnPumps = (Button) findViewById(R.id.btnPumps);
 btnPumps.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(new URLHelper().CreatePumpURL(pumpRequirement))));
 }
 });
 }


//Calculates the variables using the custom Calculate helper class (CalculateResult)
 private void Calculate(){
 CalculateHelper calcHelper = new CalculateHelper(poolSize, turnoverTime, turnoverRate);

 pumpRequirement = calcHelper.CalculatePumpRequirement();
 filterAreaRequiment = calcHelper.CalculateFilterAreaRequirement();
 minimumDiameterFilter = calcHelper.CalculateMinimumDiameterFilter();
 }

//Applies everything to the view"activity_result" after being calculated
 private void SetText(){

 resultPumpRequirement = (TextView) findViewById(R.id.resultPumpRequirement);
 resultPumpRequirement.setText(Html.fromHtml(pumpRequirement +" m<sup><small>3</small></sup> per time"));

 resultFilterAreaRequirement = (TextView) findViewById(R.id.resultFilterAreaRequirement);
 resultFilterAreaRequirement.setText(Html.fromHtml(filterAreaRequiment +" m<sup><small>2</small></sup>"));

 resultMinimumDiameterFilter = (TextView) findViewById(R.id.resultMinimumDiameterFilter);
 resultMinimumDiameterFilter.setText(minimumDiameterFilter +"mm");
 }
}

这两个类实际上在崩溃期间执行任何操作。 我找不到任何缺陷,希望你们中的一些能够发现任何 anything 。

提前致谢!

时间: 原作者:

0 0

问题解决

由于 Locale 在电话上设置为丹麦语,程序用 , 替换 .,这导致了错误。

我只是用下面的代码替换了我的代码:


//Calculates the minimum optimal filter area requirement
public double CalculateFilterAreaRequirement(){
 CalculateTurnoverPerHour();
 double tmp = turnoverPerHour/turnoverRate;
 filterAreaRequirement = Math.floor(tmp * 100)/100;
 return filterAreaRequirement;
}

原作者:
...