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

安东尼·博利

我正在为明天到期的移动应用开发最终项目开发一个 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);
    }
}

自昨天以来我唯一添加的是在“eMilesDriven”变量上设置的 TextWatcher,它将进行计算。我唯一能想到的另一件事是我今天更改了我的启动器图标,但是应用程序中的其他所有内容都可以正常工作,所以我不确定是这样。我只是不明白为什么它在我的模拟器上完美运行并在我的手机上崩溃。我已经多次重新启动 Android Studio,并从我的手机上删除了该应用程序并尝试再次启动它,但每次它都没有为我提供 logcat 错误。我很感激我能得到的任何帮助。如果我不能在明天之前解决它,我可能只需要在模拟器上展示我的应用程序,但我真的很想知道它为什么崩溃。

编辑: logcat 错误如下:

FATAL EXCEPTION: main
                                                                               Process: com.example.boley.databaseexample, PID: 15335
                                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.boley.databaseexample/com.example.boley.personaldeliveryassistant.OrderDetails}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
                                                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221)
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                   at android.os.Looper.loop(Looper.java:158)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                                   at com.example.boley.personaldeliveryassistant.OrderDetails.onCreate(OrderDetails.java:173)
                                                                                   at android.app.Activity.performCreate(Activity.java:6876)
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                   at android.os.Looper.loop(Looper.java:158) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
零一

获取当前焦点()

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

删除 getCurrentFocus() 因为它会返回 null ..

我所看到的,你所做的afterTextChanged(Editable s)是它已经指向当前的edittext ..

其他可能的空指针在这里

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

改成

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

android studio 中的 LogCat 错误,运行时应用程序崩溃

来自分类Dev

带有 Retrofit2 的 Android 应用程序崩溃而没有错误消息

来自分类Dev

Logcat错误:应用程序崩溃,无法运行。根据Logcat在setContentView发生错误

来自分类Dev

第一次Android应用程序崩溃,但代码中没有错误

来自分类Dev

Android应用程序启动后崩溃,没有任何错误

来自分类Dev

android studio 数据库应用程序崩溃没有错误

来自分类Dev

Logcat的Android SQLite错误

来自分类Dev

FileNotFoundException Android logcat错误

来自分类Dev

我的GoogleMap应用程序无法运行,但logcat中没有错误

来自分类Dev

Android第一个应用程序Hello World Logcat错误

来自分类Dev

代码没有错误,logcat 什么都没有,但不幸的是应用程序停止了错误

来自分类Dev

尽管有UncaughtExceptionHandler,但间歇性Android应用程序崩溃,没有错误日志

来自分类Dev

Android Kotlin Coroutine崩溃,但Logcat中未报告致命错误

来自分类Dev

当我的应用程序在 android oreo 8.1 上崩溃时没有错误报告

来自分类Dev

在Android应用中使用Facebook登录(logcat中无错误)

来自分类Dev

尝试从github实现CountryPicker。代码中没有错误,应用崩溃,很多logcat错误

来自分类Dev

logcat显示与我的应用程序相关的所有内容的空白窗口,但会向android studio发送不相关的错误消息

来自分类Dev

Logcat 显示我为我的 Android 应用程序创建的 SQLite 数据库的各种类型的错误

来自分类Dev

Android Studio + AVD:应用程序在模拟器中崩溃,logcat为空

来自分类Dev

我的应用停止了logcat错误

来自分类Dev

LogCat错误停止应用程序运行-添加代码

来自分类Dev

当我的应用程序运行时,为什么在Android Studio Logcat中看到“没有可调试的应用程序”?

来自分类Dev

尝试将记录插入数据库时 Android Studio 应用程序崩溃,错误消息没有意义

来自分类Dev

意外的Android应用程序终止,没有崩溃异常

来自分类Dev

Android Studio logcat打印很多错误

来自分类Dev

android appcompat_v7错误logcat

来自分类Dev

Android设备上LogCat中的许多错误

来自分类Dev

如何在Android应用程序中收集LogCat消息

来自分类Dev

Windows桌面Cordova应用程序崩溃崩溃,没有错误消息

Related 相关文章

  1. 1

    android studio 中的 LogCat 错误,运行时应用程序崩溃

  2. 2

    带有 Retrofit2 的 Android 应用程序崩溃而没有错误消息

  3. 3

    Logcat错误:应用程序崩溃,无法运行。根据Logcat在setContentView发生错误

  4. 4

    第一次Android应用程序崩溃,但代码中没有错误

  5. 5

    Android应用程序启动后崩溃,没有任何错误

  6. 6

    android studio 数据库应用程序崩溃没有错误

  7. 7

    Logcat的Android SQLite错误

  8. 8

    FileNotFoundException Android logcat错误

  9. 9

    我的GoogleMap应用程序无法运行,但logcat中没有错误

  10. 10

    Android第一个应用程序Hello World Logcat错误

  11. 11

    代码没有错误,logcat 什么都没有,但不幸的是应用程序停止了错误

  12. 12

    尽管有UncaughtExceptionHandler,但间歇性Android应用程序崩溃,没有错误日志

  13. 13

    Android Kotlin Coroutine崩溃,但Logcat中未报告致命错误

  14. 14

    当我的应用程序在 android oreo 8.1 上崩溃时没有错误报告

  15. 15

    在Android应用中使用Facebook登录(logcat中无错误)

  16. 16

    尝试从github实现CountryPicker。代码中没有错误,应用崩溃,很多logcat错误

  17. 17

    logcat显示与我的应用程序相关的所有内容的空白窗口,但会向android studio发送不相关的错误消息

  18. 18

    Logcat 显示我为我的 Android 应用程序创建的 SQLite 数据库的各种类型的错误

  19. 19

    Android Studio + AVD:应用程序在模拟器中崩溃,logcat为空

  20. 20

    我的应用停止了logcat错误

  21. 21

    LogCat错误停止应用程序运行-添加代码

  22. 22

    当我的应用程序运行时,为什么在Android Studio Logcat中看到“没有可调试的应用程序”?

  23. 23

    尝试将记录插入数据库时 Android Studio 应用程序崩溃,错误消息没有意义

  24. 24

    意外的Android应用程序终止,没有崩溃异常

  25. 25

    Android Studio logcat打印很多错误

  26. 26

    android appcompat_v7错误logcat

  27. 27

    Android设备上LogCat中的许多错误

  28. 28

    如何在Android应用程序中收集LogCat消息

  29. 29

    Windows桌面Cordova应用程序崩溃崩溃,没有错误消息

热门标签

归档