我試圖做一些事情,應該是簡單的,我的主要佈局是這樣異常
<?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