, 내 메인 레이아웃이 주요 활동에는 자바 코드가 없다이예외
<?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>
같다; 이제 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>
자바 코드 : 아래에 언급 된 어떠한 자바 코드가 없습니다로
@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 레이아웃은 간단하다. 나는 응용 프로그램을 실행할 때
<?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>
, 나는 내가 커밋() 호출을 제거하고 어쨌든 행이 성공적으로 생성 및 추가 될 때 예외가 발생하지 않습니다 원인 때문에 커밋() 호출의 예외가 계층 구조. 36 : 27.414 : E/AndroidRuntime (835) :
내가 아래 예외를 07-08 03 얻을 java.lang.RuntimeException가 : 활동 ComponentInfo {io.raindance.kalimat/io.raindance.kalimat를 시작할 수 없습니다. test.KalimatActivity} : java.lang.IllegalArgumentException : 조각에 대한 ID 0x7f050005 뷰가 발견되지 않았습니다. CellFragment {4103c790 # 1 id = 0x7f050005}나는 2 일 동안이 문제의 이유와 해결책을 찾고있었습니다.
깨끗한 프로젝트를 시도하십시오. – nhaarman