2011-07-31 92 views
3

我不斷收到試圖運行該代碼時,這個錯誤....錯誤膨脹。 ResourceNotFound異常?

07-31 10:53:40.840: ERROR/AndroidRuntime(22962): Caused by: java.lang.ClassCastException: com.fttech.shoppingClass cannot be cast to android.support.v4.app.Fragment 
07-31 10:53:40.840: ERROR/AndroidRuntime(22962):  at android.support.v4.app.Fragment.instantiate(Fragment.java:325) 
07-31 10:53:40.840: ERROR/AndroidRuntime(22962):  at android.support.v4.app.Fragment.instantiate(Fragment.java:300) 

07-31 10:50:10.650: ERROR/AndroidRuntime(22917): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070020 type #0x12 is not valid 
07-31 10:50:10.650: ERROR/AndroidRuntime(22917):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:2054) 
07-31 10:50:10.650: ERROR/AndroidRuntime(22917):  at android.content.res.Resources.getLayout(Resources.java:853) 
07-31 10:50:10.650: ERROR/AndroidRuntime(22917):  at android.view.LayoutInflater.inflate(LayoutInflater.java:389) 







public class shopping_details_fragment extends Fragment{ 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ 

    //Return the view for our WebView 
    return(inflater.inflate(R.id.shoppingWindow,container, false)); //This is where the error is pointing too 

} 

}

這裏是片段的XML我正在充氣太...

<fragment android:layout_height="match_parent" android:id="@+id/shoppingWindow" class="com.fttech.shopping_details_fragment" android:layout_width="match_parent"></fragment> 

我在做什麼錯?

回答

6

據我瞭解碎片,你需要把它看作一個活動。因此,您似乎試圖用inflater.inflate(R.id.shoppingWindow,container, false)來擴大片段。相反,你應該擴大片段的佈局,而不是片段本身。所以像inflater.inflate(R.layout.shoppingWindowLayout, container, false)這樣的東西,就像你膨脹活動的佈局一樣。

至於演員例外,shoppingClass延伸到什麼程度?確保你有正確的進口聲明。您正在使用兼容性庫,因此您的片段導入語句應該來自該庫,而不是內置於Android的片段。例如,您應該有android.support.v4.app.Fragment,可能有android.support.v4.app.FragmentActivity而不是android.app.Fragment可能是是演員例外的來源。