当前位置: 首页 > 知识库问答 >
问题:

为什么我的应用程序崩溃没有任何错误?

上官和惬
2023-03-14

应用程序崩溃,我会得到以下错误:

致命异常:主进程:com.example.ayyan.JellyBeanEstimator,pid:2960 java.lang.RuntimeException:无法启动活动

ComponentInfo{com.example.ayyan.JellyBeanEstimator/com.example.ayyan.JellyBeanEstimator.MainActivity}:java.lang.NumberFormatException:Android.app.ActivityThread.PerformLaunchActivity(ActivityThread.java:2646)在Android.app.ActivityThread.HandleLaunchActivity(ActivityThread.java:2707)在Android.app.ActivityThread.-Wrap12(ActivityThread.java)在Android.app.ActivityThreadYBeanEstimator.MainActivity.OnCreate(MainActivity.java:25)位于Android.app.Activity.PerformCreate(Activity.java:6662)位于Android.app.Instrumentation.CallActivityCreate(Instrumentation.java:1118)位于Android.app.ActivityThread.PerformLaunchActivity(ActivityThread.java:2599)位于Android.app.ActivityThread.HandleLaunchActivity(ActivityThread.java:2707) 在android.app.activitythread.-wrap12(activitythread.java) 在Android.app.ActivityThread$H.HandleMessage(ActivityThread.java:1460) 在android.os.handler.dispatchmessage(handler.java:102) 在android.os.looper.loop(looper.java:154) 在android.app.activityThread.main(activityThread.java:6077) 在java.lang.Reflect.Method.Invoke(原生方法) 在com.android.internal.os.zygoteInit$methodandargscaller.run(zygoteInit.java:865) 在com.android.internal.os.zygoteinit.main(zygoteinit.java:755)

package com.example.ayyan.jellybeanestimator;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Button;   
import android.content.Intent;
import android.view.View;

public class MainActivity extends AppCompatActivity {
EditText jellyBeanLength, jellyBeanDiameter, jarSizeVolume;
double jellybeantall, jellybeanfat, jellybeanspace;
double loadFactor = .698;
TextView answer;

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

    jellyBeanLength = (EditText) findViewById (R.id.length);
    jellyBeanDiameter = (EditText) findViewById (R.id.diameter);
    jarSizeVolume = (EditText) findViewById (R.id.jarsize);
    jellybeantall = Double.parseDouble(jellyBeanLength.getText().toString());
    jellybeanfat = Double.parseDouble(jellyBeanDiameter.getText().toString());
    jellybeanspace = Double.parseDouble(jarSizeVolume.getText().toString());
    answer = (TextView) findViewById (R.id.answer);
    Button calculate = (Button) findViewById (R.id.calculate);
    calculate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, MainActivity.class));
        }
    });



    double volumeOfOneJellyBean =  ((3.14159265359/6)*(jellybeanfat*jellybeanfat)*jellybeantall);
    double volumeofBeans = (jellybeanspace*loadFactor);
    float numberOfBeans = (float)Math.round (volumeofBeans/volumeOfOneJellyBean);
    answer.setText("You have this amount of beans in your jar" + numberOfBeans);
}

}

共有1个答案

颜森
2023-03-14

检查是否在edittext中插入了任何值,然后仅在double解析

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

        jellyBeanLength = (EditText) findViewById (R.id.length);
        jellyBeanDiameter = (EditText) findViewById (R.id.diameter);
        jarSizeVolume = (EditText) findViewById (R.id.jarsize);

        answer = (TextView) findViewById (R.id.answer);
        Button calculate = (Button) findViewById (R.id.calculate);
        calculate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

//Take out value when button pressed
        jellybeantall = Double.parseDouble(TextUtils.isEmpty(jellyBeanLength.getText().toString())?"0":jellyBeanLength.getText().toString());
        jellybeanfat = Double.parseDouble(TextUtils.isEmpty(jellyBeanDiameter.getText().toString())?"0":jellyBeanDiameter.getText().toString());
        jellybeanspace = Double.parseDouble(TextUtils.isEmpty(jarSizeVolume.getText().toString())?"0":jarSizeVolume.getText().toString());



        double volumeOfOneJellyBean =  ((3.14159265359/6)*(jellybeanfat*jellybeanfat)*jellybeantall);
        double volumeofBeans = (jellybeanspace*loadFactor);
        float numberOfBeans = (float)Math.round (volumeofBeans/volumeOfOneJellyBean);
        answer.setText("You have this amount of beans in your jar" + numberOfBeans);
            } 
        }); 
    } 
 类似资料:
  • 主要活动 公共类MainActivity扩展AppCompatActivity{String response; 公共类GetExample{OkHttpClient客户端; Xml文件

  • 注意:在我添加广告之前,我的应用程序运行良好,使用相同的方法 当我试图将adview添加到我的应用程序时,它会使我的应用程序崩溃,所以我删除了它,但仍然给我这个这是logcat 10-12 21:33:19.765 4993-4993/com。fm360。almorfis E/AndroidRuntime:致命异常:主进程:com。fm360。阿尔莫菲斯,PID:4993爪哇。lang.Runti

  • 有人能解释一下,当我尝试使用返回错误的突变时,为什么我的react应用程序apollo会这样做? GraphQL突变返回此信息(响应代码为200):<代码>{“错误”:[{“错误”:{“结果”:“身份。未找到”,“错误”:“身份验证失败”,“状态代码”:401}}}],“数据”:{“登录”:null}} 我的突变是这样的: 打电话: 它会像预期的那样运行一段时间(呈现我自己的自定义错误组件-<代码

  • 每当我请求权限时,我的应用程序就会崩溃。作为清单标记的子项,我在清单中定义了正确的使用权限。它没有给出任何错误,只是一个弹出窗口说包安装程序已经停止,监视器中有一行说“sendUserActionEvent()mView==null”,我不确定这与崩溃有关。 这是我请求权限的片段: 最低sdk设置为23,在三星Galaxy S7上进行测试。 你可以在这里看到完整的代码https://github.

  • 这就是它崩溃的地方 01-12 13:44:12.571 296 26-29688/ca.dti.grounded.app E/OtherService:AsynchChecker 287:73 java.lang.IllegalStateException:Parcel已完成!在android.os.binderproxy.transactNative(本机方法)在android.os.bind