我遇到了非常烦人的问题。我试图在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
视图,或者从其他布局中进行 inflate,设置正确的 LayoutParams 对象,并尝试将此 inflate 后的视图注入到原始布局中以替换 stub(目前我想不到更简单的方法,也不知道这是否真正可以解决它)。 - Ped7g