Android应用程序崩溃,没有logcat错误

Android应用程序崩溃,没有logcat错误,android,crash,textwatcher,Android,Crash,Textwatcher,我正在为明天到期的移动应用程序开发最终项目开发一个android应用程序,但遇到了一个问题。直到昨天,我的应用程序在我的手机上还能正常运行,但从那以后我不知怎么搞砸了。这个程序运行得很好,在模拟器上完成了我需要的一切,甚至在我昨天添加了所有东西之后,所以我认为这个应用程序已经完全完成,可以演示了。然而,我今天在手机上运行了它,发现在启动以下活动时应用程序正在崩溃 public class OrderDetails extends AppCompatActivity { private

我正在为明天到期的移动应用程序开发最终项目开发一个android应用程序,但遇到了一个问题。直到昨天,我的应用程序在我的手机上还能正常运行,但从那以后我不知怎么搞砸了。这个程序运行得很好,在模拟器上完成了我需要的一切,甚至在我昨天添加了所有东西之后,所以我认为这个应用程序已经完全完成,可以演示了。然而,我今天在手机上运行了它,发现在启动以下活动时应用程序正在崩溃

public class OrderDetails extends AppCompatActivity {

    private List<PhoneBook> contactList;
    private ListView listView;
    private TextView name, number, address, orderTotal, amountReceived, tip, mileage, grandTotal;
    private Button add;
    private PhonebookAdapter adapter;
    PhoneBookHandler db;

    double dAmountReceived;
    double dTotalCost;
    double dSubtract;
    double dMileage;
    double dGrandTotal;
    double dTip;
    double dAdd;
    double dMilesDriven;
    double dMultiply;
    double dRatePerMile;
    String sAmountReceived;
    String sTotalCost;
    String sTip;
    String sMileage;
    String sGrandTotal;
    String sAddress;
    String ratePerDelivery;
    String ratePerMile;
    String milesDriven;
    EditText eAmountReceived;
    EditText eTotalCost;
    EditText eTip;
    EditText eMileage;
    EditText eAddress;
    EditText eGrandTotal;
    EditText eMilesDriven;

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

        listView = (ListView) findViewById(R.id.contactlist);

        db = new PhoneBookHandler(this);

        contactList = db.getAllContacts();

        adapter = new PhonebookAdapter(this, contactList);

        eAddress = (EditText) findViewById(R.id.address);

        eTotalCost = (EditText) findViewById(R.id.orderTotal);
        eAmountReceived = (EditText) findViewById(R.id.amountReceived);
        eTip = (EditText) findViewById(R.id.tip);
        eMileage = (EditText) findViewById(R.id.mileage);
        eGrandTotal = (EditText) findViewById(R.id.grandTotal);
        eMilesDriven = (EditText) findViewById(R.id.milesDriven);

        // use shared preferences to inflate mileage edittext with data entered in settings menu
        ratePerDelivery = PreferenceManager.getDefaultSharedPreferences(this).getString("ratePerDeliveryPref", null);
        ratePerMile = PreferenceManager.getDefaultSharedPreferences(this).getString("ratePerMilePref", null);

        eAmountReceived.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence s, int start,
                                      int count, int after){}

            @Override
            public void onTextChanged(CharSequence s, int start,
                                  int before, int count){}

            @Override
            public void afterTextChanged(Editable s)
            {
                if (getCurrentFocus() == eAmountReceived)
                {
                    sAmountReceived = eAmountReceived.getText().toString();
                    sTotalCost = eTotalCost.getText().toString();
                    sMileage = eMileage.getText().toString();
                    sTip = eTip.getText().toString();

                    try
                    {
                        dAmountReceived = Double.parseDouble(sAmountReceived);
                        dTotalCost = Double.parseDouble(sTotalCost);

                        dSubtract = dAmountReceived - dTotalCost;
                        dMileage = Double.parseDouble(sMileage);
                        dGrandTotal = dSubtract + dMileage;
                    } catch(NumberFormatException e){}

                    sTip = String.valueOf(dSubtract);

                    DecimalFormat df = new DecimalFormat("0.00");
                    sTip = df.format(dSubtract);

                    eTip.setText(sTip);

                    sGrandTotal = String.valueOf(dGrandTotal);
                    sGrandTotal = df.format(dGrandTotal);
                    eGrandTotal.setText(sGrandTotal);
                }
            }
        });


        eTip.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence s, int start,
                                      int count, int after){}

            @Override
            public void onTextChanged(CharSequence s, int start,
                                  int before, int count){}

            @Override
            public void afterTextChanged(Editable s) {
                if (getCurrentFocus() == eTip)
                {
                    sAmountReceived = eAmountReceived.getText().toString();
                    sTotalCost = eTotalCost.getText().toString();
                    sMileage = eMileage.getText().toString();
                    sTip = eTip.getText().toString();

                    try {
                        dTip = Double.parseDouble(sTip);
                        dTotalCost = Double.parseDouble(sTotalCost);

                        dAdd = dTotalCost + dTip;
                        dMileage = Double.parseDouble(sMileage);
                        dGrandTotal = dTip + dMileage;
                    } catch (NumberFormatException e) {
                    }

                    sAmountReceived = String.valueOf(dAdd);

                    DecimalFormat df = new DecimalFormat("0.00");
                    sAmountReceived = df.format(dAdd);

                    eAmountReceived.setText(sAmountReceived);

                    sGrandTotal = String.valueOf(dGrandTotal);
                    sGrandTotal = df.format(dGrandTotal);
                    eGrandTotal.setText(sGrandTotal);
                }
            }
        });


        if (ratePerMile.equals("") && !ratePerDelivery.equals(""))
        {
            eMileage.setText(ratePerDelivery);
        }

        else
        {
            eMilesDriven.addTextChangedListener(new TextWatcher()
            {
                @Override
                public void beforeTextChanged(CharSequence s, int start,
                                          int count, int after){}

                @Override
                public void onTextChanged(CharSequence s, int start,
                                      int before, int count){}

                @Override
                public void afterTextChanged(Editable s)
                {
                    if (getCurrentFocus() == eMilesDriven)
                    {
                        sAmountReceived = eAmountReceived.getText().toString();
                        sTotalCost = eTotalCost.getText().toString();
                        sMileage = eMileage.getText().toString();
                        sTip = eTip.getText().toString();

                        try
                        {
                            milesDriven = eMilesDriven.getText().toString();
                            dMilesDriven = Double.parseDouble(milesDriven);
                            dRatePerMile = Double.parseDouble(ratePerMile);
                            dMultiply = dRatePerMile * dMilesDriven;
                            dGrandTotal = dSubtract + dMultiply;
                        } catch(NumberFormatException e){}

                        sMileage = String.valueOf(dMultiply);

                        DecimalFormat df = new DecimalFormat("0.00");
                        sMileage = df.format(dMultiply);

                        eMileage.setText(sMileage);

                        sGrandTotal = String.valueOf(dGrandTotal);
                        sGrandTotal = df.format(dGrandTotal);
                        eGrandTotal.setText(sGrandTotal);
                    }
                }
            });
        }
    }

    public void onClick(View view)
    {

        name = (EditText) findViewById(R.id.name);
        number = (EditText) findViewById(R.id.number);
        address = (EditText) findViewById(R.id.address);
        orderTotal = (EditText) findViewById(R.id.orderTotal);
        amountReceived = (EditText) findViewById(R.id.amountReceived);
        tip = (EditText) findViewById(R.id.tip);
        mileage = (EditText) findViewById(R.id.mileage);
        grandTotal = (EditText) findViewById(R.id.grandTotal);

        String cName = name.getText().toString();
        String num = number.getText().toString();
        String cAddress = address.getText().toString();
        String cOrderTotal = orderTotal.getText().toString();
        String cAmountReceived = amountReceived.getText().toString();
        String cTip = tip.getText().toString();
        String cMileage = mileage.getText().toString();
        String cGrandTotal = grandTotal.getText().toString();


        int id = db.addContact(new PhoneBook(cName, num, cAddress, cOrderTotal,
                                          cAmountReceived, cTip, cMileage, cGrandTotal));
        contactList.add(new PhoneBook(id, cName, num, cAddress, cOrderTotal,
                                   cAmountReceived, cTip, cMileage, cGrandTotal));
        adapter.notifyDataSetChanged();

        Toast.makeText(getApplicationContext(), "Entry Successfully Created.", Toast.LENGTH_LONG).show();
    }


    public void buttonClickFunction(View v)
    {
        Intent intent = new Intent(getApplicationContext(), display_database.class);
        startActivity(intent);
    }

    public void sendMessage(View v)
    {
        eAddress = (EditText) findViewById(R.id.address);
        sAddress = eAddress.getText().toString();

        String map = "http://maps.google.com/maps?q=" + sAddress;
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(map));
        startActivity(intent);
    }
}
getCurrentFocus()

返回此窗口中当前有焦点的视图,如果有,则返回null 没有。请注意,这不会在任何包含窗口中查找

删除getCurrentFocus(),因为它将返回null

我看到的是,您在
后文本更改(可编辑的)
中所做的操作,它已经指向当前的编辑文本

另一个可能的空指针在这里

if (ratePerMile.equals("") && !ratePerDelivery.equals(""))
改为

if (ratePerMile == null && ratePerDelivery != null)
getCurrentFocus()

返回此窗口中当前有焦点的视图,如果有,则返回null 没有。请注意,这不会在任何包含窗口中查找

删除getCurrentFocus(),因为它将返回null

我看到的是,您在
后文本更改(可编辑的)
中所做的操作,它已经指向当前的编辑文本

另一个可能的空指针在这里

if (ratePerMile.equals("") && !ratePerDelivery.equals(""))
改为

if (ratePerMile == null && ratePerDelivery != null)

将您的android监视器筛选器从“仅显示选定的应用程序”->“无筛选器”更改。。总有错误向你表示感谢。我不知道。我将使用stacktrace更新我的问题。将您的android监视器筛选器从“仅显示选定的应用程序”->“无筛选器”更改。。总有错误向你表示感谢。我不知道。我将用stacktrace更新我的问题。getCurrentFocus()只是我区分其他两个TextWatcher的一种方法,以避免进入无限循环。但是使用你的第二个建议奏效了!我想让EditTextPreference等于一个空字符串是可以的,但我想不行。无论如何,非常感谢你!你真的保存了我的成绩。getCurrentFocus()只是我区分其他两个TextWatcher的一种方法,以避免进入无限循环。但是使用你的第二个建议奏效了!我想让EditTextPreference等于一个空字符串是可以的,但我想不行。无论如何,非常感谢你!你真的救了我的分数。