Java - Android SDK - 不幸的是<项目名称>已崩溃错误 [英] Java - Android SDK - Unfrotunately <project name> has crashed error

查看:48
本文介绍了Java - Android SDK - 不幸的是<项目名称>已崩溃错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个小应用程序,它可以为我计算复数(除法、减法、乘法等).我没有明显的编译错误,但是当我运行程序时,我收到了一堆我无法理解或不知道如何修复的运行时错误.我错过了一些明显的东西吗?这是我的代码:

I Have been working on a small app, which can calculate complex numbers for me (division, subtraction, multiplying etc.). I have no apparent compile errors, but when i run the program I get a bunch of run-time errors which I can't understand or know how to fix. Am i missing something obvious? This is my code:

    package complex.OliverV;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    import android.widget.RadioButton;
    import android.widget.EditText;

    public class ComplexNumbersActivity extends Activity {

Button Check;
RadioButton plus, minus, multiply, div;
EditText X1,X2,Y1,Y2;
TextView Ans;
int sign;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Check = (Button) findViewById(R.id.Check);
    plus = (RadioButton) findViewById(R.id.plus);
    minus = (RadioButton) findViewById(R.id.minus);
    multiply = (RadioButton) findViewById(R.id.multiply);
    div = (RadioButton) findViewById(R.id.div);
    Ans = (TextView) findViewById(R.id.Ans);
    plus.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            sign=1;
        }


    });
    minus.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            sign=2;
        }


    });
    multiply.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            sign=3;
        }


    });
    div.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            sign=4;
        }


    });
    Check.setOnClickListener(new View.OnClickListener(){

        String xs=X1.getText().toString();
        String xss=X2.getText().toString();
        String ys=Y1.getText().toString();
        String yss=Y2.getText().toString();



        double x3,y3;

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(xs!="" && xss!="" && ys!="" && yss!="")
            {
            double x1=Double.parseDouble(xs);
            double x2=Double.parseDouble(xss);
            double y1=Double.parseDouble(ys);
            double y2=Double.parseDouble(yss);
            switch(sign)
            {
            case(1):
            {
                x3=x1+x2;
                y3=y1+y2;
            }
            case(2):
            {
                x3=x1-x2;
                y3=y1-y2;
            }
            case(3):
            {
                x3=(x1*x2-y1*y2);
                y3=(x2*y1 + x1*y2);
            }
            case(4):
            {
                if(x2!=0 && y2!=0)
                {
                x3 = (x1 * x2 + y1 * y2) / (x2 * x2 + y2 * y2);
                y3 = (x2 * y1 - x1 * y2) / (x2 * x2 + y2 * y2);
                }
                else
                {
                    Ans.setText("Enter valid numbers!");
                }
            }
        }
            Ans.setText("x="+x3+"y="+y3);
        }
            else
            {
                Ans.setText("Enter valid numbers!");
            }

        }
    });
}

}

我还添加了我得到的错误的屏幕截图.我放了一张图片,因为复制文本看起来一团糟.抱歉问了这么长的问题,感谢任何能花时间帮助我的人,我非常感谢每一点帮助.:)

I am also adding a screenshot of the errors I get. Im putting an image, because copying the text looks like a mess. Sorry for the long question and thank you to anyone who can take the time to help me out, I am very grateful for every bit of help. :)

推荐答案

初始化 X1,X2,Y1,Y2 在你的 onCreate() 中,正如 Ted Hopp 在他的回答然后

initialize X1,X2,Y1,Y2 in your onCreate() as Ted Hopp mentioned in his answer and then

改变这个:

if(xs!="" && xss!="" && ys!="" && yss!="")

到:

if( (xs != null && !xs.equal("")) && 
    (xss != null && !xss.equal("")) && 
    (ys !== null && !ys.equal("")) && 
    (yss != null &&!yss.equal("")) )

这篇关于Java - Android SDK - 不幸的是<项目名称>已崩溃错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆