我试图做一些事情,应该是简单的,我的主要布局是这样异常
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:name="io.raindance.kalimat.grid.GridFragment"
android:id="@+id/gridControlInMainView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
有主活动没有Java代码;现在GridFragment的代码和布局仅仅是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridFragmentMainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
</LinearLayout>
Java代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Load the layout of the rack tile
View view = inflater.inflate(R.layout.grid_fragment, null, false);
// Get the root linear layout to add the rows to it
LinearLayout root = (LinearLayout) view.findViewById(R.id.gridFragmentMainContainer);
// Build the rows of the grid
int rowsId = 21;
for (int i = 0; i < 15; i++) {
// Create the linear layout that represents a row in the grid
LinearLayout row = new LinearLayout(this.getActivity());
row.setId(rowsId++);
row.setOrientation(LinearLayout.HORIZONTAL);
row.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 10, 1.0f));
// Build the cells of the grid
for (int j = 0; j < 15; j++) {
// Create the cell fragment
CellFragment cellFragment = new CellFragment();
// Add the cell fragment to the row fragment
this.getFragmentManager().beginTransaction().add(row.getId(), cellFragment).commit();
}
// Add the row to the root element
root.addView(row);
}
return view;
}
的CellFragment布局非常简单,只需以下提到,有没有Java代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lll1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent">
</LinearLayout>
当我运行应用程序,我得到一个例外,因为提交()的调用,导致异常不会引发当我删除了提交()调用反正行正在成功地创建并添加到层次结构。
我收到以下异常 07-08 03:36:27.414:E/AndroidRuntime(835):java.lang.RuntimeException:无法启动活动ComponentInfo {io.raindance.kalimat/io.raindance.kalimat。 test.KalimatActivity}:java.lang.IllegalArgumentException:没有找到id为0x7f050005的片段CellFragment {4103c790#1 id = 0x7f050005}
我一直在寻找这个问题的原因和解决方案,现在两天了。
尝试一个干净的项目 – nhaarman 2012-07-08 00:52:19