爪哇 - Android SDK中 - Unfrotunately<项目名称>崩溃错误 [英] Java - Android SDK - Unfrotunately <project name> has crashed error

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

问题描述

我一直在一个小的应用程序,它可以计算复数对我来说(除法,减法,乘法等)。我没有明显的编译错误,但是当我运行程序,我得到了一堆,我无法理解或不知道如何解决运行时错误的。我失去了一些东西明显?这是我的code:

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()特德·霍普在他的答复中提到,然后

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("")) )

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

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