當試圖向我的類添加一個片段我不斷收到此錯誤im不知道如何解決此im相當確定即時添加片段的權利但錯誤不斷出現,並崩潰我的應用程序時,我試圖運行它任何想法如何解決它?二進制XML文件行#9:二進制XML文件行#9:錯誤擴展類片段
XML文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_default"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ericvuu.whatsfordinner.RecipeActivity">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.ericvuu.whatsfordinner.RecipeActivity"/>
<Button
android:id="@+id/recipe1"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginBottom="484dp"
android:background="@android:color/darker_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintHorizontal_bias="0.0" />
<Button
android:id="@+id/recipe2"
android:layout_width="0dp"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recipe1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<Button
android:id="@+id/recipe3"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="-11dp"
android:background="@android:color/darker_gray"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recipe2"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
</android.support.constraint.ConstraintLayout>
的Java文件
package com.example.ericvuu.whatsfordinner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class RecipeActivity extends AppCompatActivity {
public Button recipeText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe);
recipeText = (Button) findViewById(R.id.recipe1);
try {
String message;
FileInputStream fis = openFileInput("RecipeText");
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
while ((message = br.readLine()) != null) {
sb.append(message + "\n");
}
recipeText.setText(sb.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void onClick(View v) {
}
}
和景觀xml文件IM triyng把片段
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<fragment
android:id="@+id/layout_default"
android:name="com.example.ericvuu.whatsfordinner.RecipeActivity"
android:layout_width="214dp"
android:layout_height="match_parent"
android:layout_weight="0.08" />
</LinearLayout>
'RecipeActivity'是一個'Activity'。它不是一個「片段」。你不能把它當作'片段'。此外,無論何時出現'InflateException',您都需要在堆棧跟蹤中進一步查看實際原因。 InflateException本身並沒有給你太多的提示。 –