字符串未转换为整数 - 应用程序崩溃。 [英] String is not converting to integer - app crashes.

查看:60
本文介绍了字符串未转换为整数 - 应用程序崩溃。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个editText,输入类型是数字,我尝试使用if语句,例如if(edtTxt> 20000){//执行此操作}但每次都崩溃,任何想法都是什么问题?请注意,我通过多项活动发送此Integer。



我尝试过:



So i have an editText and the inputtype is "number", i try to use an if statement for it such as if (edtTxt > 20000 ) { // do this } but it crashes every time, any idea's what's the issue? please note that i'm sending this Integer through multiple activities.

What I have tried:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_fre_quency_manual);



       btnEnter = (Button) findViewById(R.id.enter);
        btnClear = (Button) findViewById(R.id.clear);

        edtTxt = (EditText) findViewById(R.id.edtText);













        btnClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                edtTxt.setText("");


            }
        });





        btnEnter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {



                AlertDialog.Builder builder = new AlertDialog.Builder(FreQuencyManual.this);
                builder.setTitle(" Confirmation ");
                builder.setMessage("Frequency scale : " + " " + edtTxt.getText().toString() + " " +"Are you sure?");


                builder.setPositiveButton(" Yes ", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {




                        if (edtTxt.getText().toString().matches("")){



                            Toast.makeText(getApplicationContext(), " Type the frequency scale first! ", Toast.LENGTH_SHORT).show();





                        }else {

                            Intent intentMove2 = new Intent(FreQuencyManual.this,Correction.class);
                            intentMove2.putExtra("msger",edtTxt.getText().toString());
                            startActivity(intentMove2);


                        }


                    }
                });

                builder.setNegativeButton(" No ", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                        dialogInterface.cancel();



                    }
                });




                AlertDialog dialog = builder.create();
                dialog.show();

            }




        });






                }}










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


        gifImageView = (GifImageView) findViewById(R.id.gifBruhhhh);
        txtInsert = (TextView) findViewById(R.id.checkInsertedFrequency);




        Bundle bundle = getIntent().getExtras();
        String data = bundle.getString("msger");



        int nurse = Integer.parseInt(data);

        if (nurse<=20000 && nurse>=0){


            Intent intent = new Intent(Correction.this,LoadingOld.class);
            startActivity(intent);



        }else {


            Intent intent2 = new Intent(Correction.this,FreQuencyManual.class);
            startActivity(intent2);

        }







    }
}

推荐答案

如果您的应用在转换时崩溃...这意味着您的输入不是有效整数。但是,如果您认为它应该是这样,请使用调试器步进到执行解析的行,然后查看作为参数传递给解析函数的确切内容。根据该值,您可以尝试找出它的来源 - 例如,通过对早期步骤进行进一步调试。
If your app crashes when you do the conversion... it means your input isn't a valid integer. However if you believe that it should be, use your debugger to step to the line where you perform the parsing, then look at what exactly gets passed as argument to the parsing function. Based on that value, you can try to figure out where it comes from - by doing further debugging on earlier steps for example.


这篇关于字符串未转换为整数 - 应用程序崩溃。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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