开发者

Error inflating. ResourceNotFound Exception?

I keep getting this error when trying to run this code....

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)

and

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

}

}

Here is the fragment xml i am inflating too...

<fragment android:layout_height="match_parent" android:id="@+id/shoppingWindow" class="com.fttech.shopping_details_fragment" android:layout_width="match_parent">&l开发者_如何学Ct;/fragment>

What am i doing wrong?


As far as I understand Fragments, you need to think of this as an Activity. Thus, it appears that you are trying to inflate a fragment with inflater.inflate(R.id.shoppingWindow,container, false). Rather, you should be inflating the layout for the fragment, not the fragment itself. So something like inflater.inflate(R.layout.shoppingWindowLayout, container, false), just as you would inflate the layout for an activity.

As for the cast exception, what does shoppingClass extend? Make sure you have the correct import statements. You are using the compatibility library so your import statements for fragments should be from that rather than the fragments built in to Android. For example, you should have android.support.v4.app.Fragment and probably android.support.v4.app.FragmentActivity rather than android.app.Fragment. That might be the source of the cast exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜