2011-05-17 24 views
0

膨脹佈局我試圖膨脹包含類的佈局。 我創建吹氣如:LayoutInflater未能通過參考類

LayoutInflater inflate =(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
mRelLayout = (RelativeLayout) inflate.inflate(
        R.layout.app_layout, null); 

我app_layout.xml佈局是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:panel="http://schemas.android.com/apk/res/com.alpha" 
      android:id="@+id/layoutMain" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:gravity="top|right"> 

。 。 。

通貨膨脹失敗例外:了java.lang.RuntimeException:您的面板必須有一個孩子查看其id屬性是「R.id.panelHandle」

感謝您的幫助

+0

我不認爲它在這一行中有錯誤。我看不到關於panelHandle控制的代碼。你可以發送logcat嗎? – bonnie 2013-01-18 08:10:01

回答

0

我曾嘗試以下代碼,它工作的很好,請提供完整的源代碼,以便我可以識別錯誤。

Test.java

LayoutInflater inflate =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
    RelativeLayout mRelLayout = (RelativeLayout) inflate.inflate(
         R.layout.app_layout, null); 

app_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:panel="http://schemas.android.com/apk/res/com.alpha" 
      android:id="@+id/layoutMain" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:gravity="top|right" /> 
0

你有沒有tryed刪除xmlns:panel="http://schemas.android.com/apk/res/com.alpha"

你可以發佈整個佈局嗎?