Android 充气异常:二进制XML文件
这就是我犯的错误Android 充气异常:二进制XML文件,android,fragment,android-inflate,Android,Fragment,Android Inflate,这就是我犯的错误 12-05 13:26:18.102: E/AndroidRuntime(10101): FATAL EXCEPTION: main 12-05 13:26:18.102: E/AndroidRuntime(10101): Process: com.example.project_1_4, PID: 10101 12-05 13:26:18.102: E/AndroidRuntime(10101): java.lang.RuntimeException: Unable to s
12-05 13:26:18.102: E/AndroidRuntime(10101): FATAL EXCEPTION: main
12-05 13:26:18.102: E/AndroidRuntime(10101): Process: com.example.project_1_4, PID: 10101
12-05 13:26:18.102: E/AndroidRuntime(10101): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.project_1_4/
com.example.project_1_4.MainActivity}: android.view.InflateException: Binary XML file line #14:
Error inflating class fragment
我的xml文件——我想我发帖时遗漏了括号。现在我纠正它
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="410dp" >
</ListView>
</LinearLayout>
源代码
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.zip.Inflater;
import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class Dday_fragment extends ListFragment{
ArrayList<Detail> detailList = new ArrayList<Detail>();
ArrayList<String> detailName = new ArrayList<String>();
DetailOperation DetailDBOperation;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = new View(getActivity());
try{
view = inflater.inflate(R.layout.dday_fragment, container, false);
}catch (InflateException e){
}
DetailDBOperation = new DetailOperation(null);
try {
DetailDBOperation.open();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(DetailDBOperation.getAllDetail()!=null){
detailList = DetailDBOperation.getAllDetail();
}else{
detailList = null;
}
int size = detailList.size();
for(int i = 0; i < size; i++){
detailName.add(detailList.get(i).getSubjectName());
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, detailName);
setListAdapter(adapter);
return view;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Detail_fragment dtf = (Detail_fragment) getFragmentManager().findFragmentById(R.layout.detail_fragment);
dtf.change(position);
getListView().setSelector(android.R.color.holo_red_dark);
}
}
import java.sql.SQLException;
导入java.util.ArrayList;
导入java.util.zip.Inflater;
导入android.app.ListFragment;
导入android.content.Context;
导入android.os.Bundle;
导入android.view.InflateException;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.ListView;
公共类Dday_片段扩展了ListFragment{
ArrayList detailList=新的ArrayList();
ArrayList detailName=新的ArrayList();
DetailOperation DetailDBOperation;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//TODO自动生成的方法存根
视图=新视图(getActivity());
试一试{
视图=充气机。充气(R.layout.dday_碎片,容器,假);
}锁扣(充气异常e){
}
DetailDBOperation=新的DetailOperation(空);
试一试{
DetailDBOperation.open();
}捕获(SQLE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
if(DetailDBOperation.getAllDetail()!=null){
detailList=DetailDBOperation.getAllDetail();
}否则{
detailList=null;
}
int size=detailList.size();
对于(int i=0;i
这是Dday_fragment.java的完整代码
如果不使用ListFragment,如何使用onListItemClick?
我想在dday_片段中显示项目列表,
还有另一个xml随用户选择的项目id而变化。
另一个xml将显示项目的详细信息。
因此,我使用onListItemClick在另一个xml上更改和设置文本。您需要为线性布局使用标记
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
布局XML文件有问题。确保关闭已打开的支架。这是你错过的
<LinearLayout> </LinearLayout>
另一种方法是:
<LinearLayout />
您忘记声明属性end CONNECT。请按以下方式操作:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="410dp" >
</ListView>
</LinearLayout>
您可以发布dday_片段的完整xml代码吗?如果您使用ListFragment
扩展片段,则无需在xml文件中使用ListView
。这是完整的xml代码,hahai认为在我发布时它被意外删除。在这个onCreateView的末尾,我不需要返回视图吗?如果我这样做,它会说“视图不能作为变量解析”。返回视图;我想是不小心擦掉的ㅠㅠ
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="410dp" >
</ListView>
</LinearLayout>