我在StackOverflow中看到了很多这些错误,但没有一个解决方案适合我。似乎这个例外被抛出了许多可能的错误,并没有真正告诉你任何事情。重现的步骤
这里的视图失败了:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/toolbar_layout">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
local:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content_frame"
android:layout_below="@id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text Hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text Hello" />
<android.support.v7.widget.DropDownListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/dropDownListView1" />
</LinearLayout>
</FrameLayout>
</RelativeLayout>
我立刻得到了InflateException。
以下是logcat的一些片段,可能会给出一个指示:
03-16 14:50:35.621 20884 20884 I MonoDroid: UNHANDLED EXCEPTION:
03-16 14:50:35.641 20884 20884 I MonoDroid: Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.DropDownListView ---> Java.Lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
03-16 14:50:35.641 20884 20884 I MonoDroid: --- End of inner exception stack trace ---
和
03-16 14:50:35.641 20884 20884 I MonoDroid: --- End of managed Android.Views.InflateException stack trace ---
03-16 14:50:35.641 20884 20884 I MonoDroid: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.DropDownListView
03-16 14:50:35.641 20884 20884 I MonoDroid: at android.view.LayoutInflater.createView(LayoutInflater.java:640)
03-16 14:50:35.641 20884 20884 I MonoDroid: at mvvmcross.binding.droid.views.MvxLayoutInflater_PrivateFactoryWrapper2.n_onCreateView(Native Method)
和
03-16 14:50:35.651 20884 20884 I MonoDroid: UNHANDLED EXCEPTION:
03-16 14:50:35.651 20884 20884 I MonoDroid: Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.v7.widget.DropDownListView ---> Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.DropDownListView ---> Java.Lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
03-16 14:50:35.651 20884 20884 I MonoDroid: --- End of inner exception stack trace ---
03-16 14:50:35.651 20884 20884 I MonoDroid: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8c304e4006094a46a7950338a3b3cb5d>:0
我也经常看到这些行:
03-16 14:50:35.601 20884 20884 I AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
03-16 14:50:35.611 20884 20884 W art : Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
我在项目中搜索了app:theme但没有找到。
答案 0 :(得分:2)
如错误堆栈跟踪中所示:
Java.Lang.NoSuchMethodException:[class android.content.Context,interface android.util.AttributeSet]
这意味着,解析后的xml
框架会尝试使用接受Context
和AttributeSet
的构造函数为类android.support.v7.widget.DropDownListView
创建一个java对象,这显然不会不存在。
只要它有一个带有签名public DropDownListView(Context context, boolean hijackFocus)
的构造函数,我相信你必须在运行时通过Java代码创建它。