예외

2012-07-08 4 views
0
나는 간단해야 뭔가를하려고

, 내 메인 레이아웃이 주요 활동에는 자바 코드가 없다이예외

<?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 일 동안이 문제의 이유와 해결책을 찾고있었습니다.

+0

깨끗한 프로젝트를 시도하십시오. – nhaarman

답변

0

FragmentTransaction을 수행하려면 Activity을 만들고 (상태를 저장해야합니다.) 그렇지 않으면 예외가 발생합니다. 대신 onActivityCreated에서 거래를 시도하십시오.

+0

작동하지 않습니다. 여전히 동일한 예외가 발생합니다. –

+0

코드는 조각 내에 조각을 포함하려고 시도합니다. 새로운 셀 조각을 인스턴스화하고이를 부모보기에 추가하려고 시도해서는 안됩니다. 이것은 아마 당신이 예외를 얻는 이유입니다 ... 당신은 단편 내에 조각이 존재할 수 없습니다. 개발자 사이트에서 파편을 읽는 것을 고려해야합니다. –

+0

나는 이것이 다른 조각들 안에 조각을 설정할 수 없다고 생각한다. 고마워. –