I am facing a very annoying situation. I am trying display an alert dialog with DatePicker and TimePicker. It works on every device except some Samsung Devices (And according to the crash reports I received, all of them are Android Version 6.0.1).
Here is the crash report:
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
Here is my code:
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();
}
}
And here is the layout I am trying to inflate:
<?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>
Please Help!
PS: I received this crash report using ACRA crash reporting system in my app.
Strangely, I started seeing this crash only recently. My attempted workaround is to subclass TimePicker and catch the crash. Unfortunately I do not have access to any of the affected devices (Galaxy J1, Galaxy J3, Galaxy On7 Pro, Galaxy A7) for validating this approach.
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)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With