我一直试图解决这个问题一整天了.我在Android Studio中创建了一个新项目,并选择了标签导航活动.从那里我在fragment_main.xml的XML中添加了一个简单的EditText并运行它.它总是给我一个EditText充气错误.任何其他元素(例如TextViews)都不会发生这种情况
fragment_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="packagename.MainActivity$PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/editText3" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Gradle依赖项:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
}
Run Code Online (Sandbox Code Playgroud)
logcat的:
Process: <package name>, PID: 20764
android.view.InflateException: Binary XML file line #16: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at <package name>.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:119)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at …Run Code Online (Sandbox Code Playgroud)