Timepicker似乎在使用Android版本6.0.1的Samsung Devices上崩溃我的应用程序

时间:2017-03-03 13:17:29

标签: android nullpointerexception crash timepicker

我面临一个非常烦人的情况。我正在尝试使用DatePicker和TimePicker显示警告对话框。除了一些三星设备之外,它适用于所有设备(根据我收到的崩溃报告,所有这些都是Android版本6.0.1)。

以下是崩溃报告:

EventEmitter

这是我的代码:

USER_COMMENT=null
STACK_TRACE=android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class android.widget.TimePicker
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at ankit.inventory.ankitarora.inventorymanagementsimple.ManageTransactions.askTimestamp(ManageTransactions.java:385)
at ankit.inventory.ankitarora.inventorymanagementsimple.ManageTransactions$3.onClick(ManageTransactions.java:324)
at android.view.View.performClick(View.java:5698)
at android.view.View$PerformClick.run(View.java:22538)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
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: android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.TimePicker
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
... 13 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
... 22 more
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void android.widget.TimePicker$TimePickerDelegate.onRtlPropertiesChanged(int)' on a null object reference
at android.widget.TimePicker.onRtlPropertiesChanged(TimePicker.java:248)
at android.view.View.resolvePadding(View.java:15609)
at android.view.ViewGroup.resolvePadding(ViewGroup.java:6877)
at android.view.View.initializeScrollbarsInternal(View.java:5342)
at android.view.View.<init>(View.java:4677)
at android.view.ViewGroup.<init>(ViewGroup.java:591)
at android.widget.FrameLayout.<init>(FrameLayout.java:97)
at android.widget.TimePicker.<init>(TimePicker.java:78)
at android.widget.TimePicker.<init>(TimePicker.java:74)
at android.widget.TimePicker.<init>(TimePicker.java:70)
... 24 more
android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.TimePicker
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at ankit.inventory.ankitarora.inventorymanagementsimple.ManageTransactions.askTimestamp(ManageTransactions.java:385)
at ankit.inventory.ankitarora.inventorymanagementsimple.ManageTransactions$3.onClick(ManageTransactions.java:324)
at android.view.View.performClick(View.java:5698)
at android.view.View$PerformClick.run(View.java:22538)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
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.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
... 22 more
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void android.widget.TimePicker$TimePickerDelegate.onRtlPropertiesChanged(int)' on a null object reference
at android.widget.TimePicker.onRtlPropertiesChanged(TimePicker.java:248)
at android.view.View.resolvePadding(View.java:15609)
at android.view.ViewGroup.resolvePadding(ViewGroup.java:6877)
at android.view.View.initializeScrollbarsInternal(View.java:5342)
at android.view.View.<init>(View.java:4677)
at android.view.ViewGroup.<init>(ViewGroup.java:591)
at android.widget.FrameLayout.<init>(FrameLayout.java:97)
at android.widget.TimePicker.<init>(TimePicker.java:78)
at android.widget.TimePicker.<init>(TimePicker.java:74)
at android.widget.TimePicker.<init>(TimePicker.java:70)
... 24 more
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at ankit.inventory.ankitarora.inventorymanagementsimple.ManageTransactions.askTimestamp(ManageTransactions.java:385)
at ankit.inventory.ankitarora.inventorymanagementsimple.ManageTransactions$3.onClick(ManageTransactions.java:324)
at android.view.View.performClick(View.java:5698)
at android.view.View$PerformClick.run(View.java:22538)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
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 interface method 'void android.widget.TimePicker$TimePickerDelegate.onRtlPropertiesChanged(int)' on a null object reference
at android.widget.TimePicker.onRtlPropertiesChanged(TimePicker.java:248)
at android.view.View.resolvePadding(View.java:15609)
at android.view.ViewGroup.resolvePadding(ViewGroup.java:6877)
at android.view.View.initializeScrollbarsInternal(View.java:5342)
at android.view.View.<init>(View.java:4677)
at android.view.ViewGroup.<init>(ViewGroup.java:591)
at android.widget.FrameLayout.<init>(FrameLayout.java:97)
at android.widget.TimePicker.<init>(TimePicker.java:78)
at android.widget.TimePicker.<init>(TimePicker.java:74)
at android.widget.TimePicker.<init>(TimePicker.java:70)
... 24 more
java.lang.NullPointerException: Attempt to invoke interface method 'void android.widget.TimePicker$TimePickerDelegate.onRtlPropertiesChanged(int)' on a null object reference
at android.widget.TimePicker.onRtlPropertiesChanged(TimePicker.java:248)
at android.view.View.resolvePadding(View.java:15609)
at android.view.ViewGroup.resolvePadding(ViewGroup.java:6877)
at android.view.View.initializeScrollbarsInternal(View.java:5342)
at android.view.View.<init>(View.java:4677)
at android.view.ViewGroup.<init>(ViewGroup.java:591)
at android.widget.FrameLayout.<init>(FrameLayout.java:97)
at android.widget.TimePicker.<init>(TimePicker.java:78)
at android.widget.TimePicker.<init>(TimePicker.java:74)
at android.widget.TimePicker.<init>(TimePicker.java:70)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at ankit.inventory.ankitarora.inventorymanagementsimple.ManageTransactions.askTimestamp(ManageTransactions.java:385)
at ankit.inventory.ankitarora.inventorymanagementsimple.ManageTransactions$3.onClick(ManageTransactions.java:324)
at android.view.View.performClick(View.java:5698)
at android.view.View$PerformClick.run(View.java:22538)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
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)

CUSTOM_DATA=
PHONE_MODEL=SAMSUNG-SM-T377A
BRAND=samsung
ANDROID_VERSION=6.0.1
APP_VERSION_NAME=3.1.0

这是我试图夸大的布局:

public void askTimestamp(final String transaction_type, final String item_name, final int integerItems, final EditText item_count, final int newItemCount, final TextView textBox_count)
{
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle("Enter Transaction Details");
    View view = getLayoutInflater().inflate(R.layout.dialog_date_time, null);
    final CustomDatePicker datePicker = (CustomDatePicker) view.findViewById(R.id.datePicker);
    final TimePicker timePicker = (TimePicker) view.findViewById(R.id.timePicker);
    dialog.setView(view);
    dialog.setPositiveButton(getString(R.string.done), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            String day = "";
            String month = "";
            String year = "";
            String hours = "";
            String minutes = "";
            String seconds = "00";
            day = datePicker.getDayOfMonth() + "";
            if (day.length() == 1)
            {
                day = "0" + day;
            }
            int actualMonth = datePicker.getMonth() + 1;
            month = actualMonth + "";
            if (month.length() == 1)
            {
                month = "0" + month;
            }
            year = datePicker.getYear() + "";
            if (year.length() == 3)
            {
                year = "0" + year;
            }
            else if(year.length() == 2)
            {
                year = "00" + year;
            }
            else if(year.length() == 1)
            {
                year = "000" + year;
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            {
                hours = timePicker.getHour() + "";
                minutes = timePicker.getMinute() + "";
            }
            else
            {
                hours = timePicker.getCurrentHour() + "";
                minutes = timePicker.getCurrentMinute() + "";
            }
            if (hours.length() == 1)
            {
                hours = "0" + hours;
            }
            if (minutes.length() == 1)
            {
                minutes = "0" + minutes;
            }
            String dateTime = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
            dbHelper.updateItem(item_name, newItemCount);
            dbHelper.createTransaction(transaction_type, item_name, integerItems, dateTime);
            if (transaction_type.equals("add"))
            {
                Toast.makeText(MyApp.getContext(), getString(R.string.transaction_adding) + " " + item_name.trim() + " " + getString(R.string.succeeded) + "!", Toast.LENGTH_SHORT).show();
            }
            else
            {
                Toast.makeText(MyApp.getContext(), getString(R.string.transaction_removing) + " " + item_name.trim() + " " + getString(R.string.succeeded) + "!", Toast.LENGTH_SHORT).show();
            }
            item_count.setText("");
            textBox_count.setText(newItemCount + "");
            dialog.cancel();
        }
    });
    dialog.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id)
                {
                    // User cancelled the dialog
                    dialog.dismiss();
                }
    });
    AlertDialog dialog_created = dialog.create();
    if (!this.isFinishing())
    {
        dialog_created.show();
    }
}

请帮忙!

PS:我在我的应用程序中使用ACRA崩溃报告系统收到了此崩溃报告。

1 个答案:

答案 0 :(得分:2)

奇怪的是,我是最近才开始看到此崩溃的。我尝试的解决方法是将TimePicker子类化并捕获崩溃。不幸的是,我无法使用任何受影响的设备(Galaxy J1,Galaxy J3,Galaxy On7 Pro,Galaxy A7)来验证此方法。

class TimePicker(context: Context, attrs: AttributeSet?) : android.widget.TimePicker(context, attrs) {
    override fun onRtlPropertiesChanged(layoutDirection: Int) {
        try {
            super.onRtlPropertiesChanged(layoutDirection)
        } catch (e: Exception) {
            Timber.e(e)
        }
    }
}