android - Timepicker 似乎在使用 Android 版本 6.0.1 的三星设备上使我的应用程序崩溃

标签 android nullpointerexception crash timepicker

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

这是崩溃报告:

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();
    }
}

这是我试图膨胀的布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ankit.inventory.ankitarora.inventorymanagementsimple.CustomDatePicker
        android:id="@+id/datePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:theme="@android:style/Theme.Holo.Light" >
    </ankit.inventory.ankitarora.inventorymanagementsimple.CustomDatePicker>

    <TimePicker
        android:id="@+id/timePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/datePicker"
        android:scrollbars="vertical"
        android:theme="@android:style/Theme.Holo.Light" >
    </TimePicker>

</RelativeLayout>

请帮忙!

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

最佳答案

奇怪的是,我最近才开始看到这种崩溃。我尝试的解决方法是继承 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)
        }
    }
}

关于android - Timepicker 似乎在使用 Android 版本 6.0.1 的三星设备上使我的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42579936/

相关文章:

android - "/system/bin/linker: No such file or directory"尝试编译 TensorFlow 时出错

android - 在哪里为耗时的操作启动新线程更好?

android 信用卡扫描库或任何 API(Card.io 除外)

抽屉导航中的 Java.lang.NullPointerException

android - setImageResource到drawables数组会引发nullpointer异常

ios - 当用户通过语音输入时,应用程序崩溃 uitextview

winapi - Nasm ReadConsoleInput

java - Android按钮文字和HTML上标和下标

java - Java Sonar NullPointerException

python - 我是Python的新手,并在程序中添加了一行代码后成功使IDLE崩溃