I'm trying to inflate a layout to use as the content for an AlertDialog
. I'm using the following code:
View dialog_view = ((LayoutInflater) builder.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.my_dialog, null);
At this line, the following exception is thrown:
Process: myname.myapp, PID: 12068
android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at myname.myapp.myclass.myfunction(myclass.java:106)
at myname.myapp.myclass.myfunction(myclass.java:52)
at myname.myapp.myotherclass.myotherfunction(myotherclass.java:188)
at myname.myapp.myotherclass$4$1.run(myotherclass.java:218)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at myname.myapp.myclass.myfunction(myclass.java:106)
at myname.myapp.myclass.myfunction(myclass.java:52)
at myname.myapp.myotherclass.myotherfunction(myotherclass.java:188)
at myname.myapp.myotherclass$4$1.run(myotherclass.java:218)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 84
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:569)
at android.view.View.<init>(View.java:3740)
at android.view.ViewGroup.<init>(ViewGroup.java:497)
at android.widget.LinearLayout.<init>(LinearLayout.java:200)
at android.widget.LinearLayout.<init>(LinearLayout.java:196)
at android.widget.LinearLayout.<init>(LinearLayout.java:192)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at myname.myapp.myclass.myfunction(myclass.java:106)
at myname.myapp.myclass.myfunction(myclass.java:52)
at myname.myapp.myotherclass.myotherfunction(myotherclass.java:188)
at myname.myapp.myotherclass$4$1.run(myotherclass.java:218)
at java.lang.Thread.run(Thread.java:818)
I've also tried using
View.inflate(this.activity, R.layout.my_dialog, null);
and with passing a ViewGroup
as the last parameter instead of null
but these throw the same exception, and by using dialog.setContentView(R.layout.my_dialog)
on the resulting dialog but this throws the same exception at the line where setContentView
is called (because presumably this inflates the layout the same way internally).
EDIT: I've also tried
this.activity.getLayoutInflater().inflate(R.layout.dialog_password, null)
and the same exception is thrown.
This is the contents of my_dialog.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/dialog_padding">
<EditText android:id="@+id/my_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/my_hint"/>
</LinearLayout>