Sunday, March 18, 2012

Re: [android-developers] ListFragment fails on setContentView

<ListFragment> is not a valid element. That says "hey, go find
android.view.ListFragment and use it here", and there is no such
class.

You add fragments to a layout via <fragment>:

http://developer.android.com/guide/topics/fundamentals/fragments.html#Adding

On Sun, Mar 18, 2012 at 7:29 AM, Jim Andresakis <jimandresakis@gmail.com> wrote:
> Ive been trying to get a listview working within a fragment all day. I dont
> know why but for some reason the way Im trying to do it, it just never wants
> to inflate the view. Im using actionbarsherlock if that makes a difference
> but I dont think so. Heres the class where my layout fails:
>
>      public class GraffSearch extends FragmentActivity implements
> ActionBar.TabListener{
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.searchlayout);//<-------------fails here
> final ActionBar ab = getSupportActionBar();
>
> for (int i = 1; i < 4; i++) {
> ab.addTab(ab.newTab().setText("Tab " + i).setTabListener(this));
> }
>
>
>         ab.show();
>         if (ab.getNavigationMode() != ActionBar.NAVIGATION_MODE_TABS) {
> ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
> }
>
> }
>
> @Override
> public void onTabReselected(Tab tab, FragmentTransaction ft) {
> // TODO Auto-generated method stub
> }
>
> @Override
> public void onTabSelected(Tab tab, FragmentTransaction ft) {
> //Toast.makeText(this, "tabs work "+tab.getPosition()+" user id is "+avrid,
> Toast.LENGTH_LONG).show();
> SearchListFrag fragment = (SearchListFrag)
> getSupportFragmentManager().findFragmentById(R.id.searchfrag);
> //fragment.updateUrl(tab.getPosition(), avrid);
> }
>
> @Override
> public void onTabUnselected(Tab tab, FragmentTransaction ft) {
> // TODO Auto-generated method stub
> }
> }
>
>
> and heres the layout were I call my fragment.
>
>     <?xml version="1.0" encoding="utf-8"?>
>     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
>     android:layout_width="match_parent"
>     android:layout_height="match_parent"
>     android:orientation="vertical"
>     >
>
>
>     <ListFragment
>         android:id="@+id/searchfrag"
>         android:layout_width="0dip"
>         android:layout_height="match_parent"
>         android:name="graffit.main.SearchListFrag"
>         android:layout_weight="1"></ListFragment>
>
>
>
>     </LinearLayout>
>
>
> Ive tried a few different setups going back and forth from using a regular
> fragment and a listfragment with the same result. Heres the logcat.
>
>     03-18 03:38:49.363: E/AndroidRuntime(8385): FATAL EXCEPTION: main
>     03-18 03:38:49.363: E/AndroidRuntime(8385): java.lang.RuntimeException:
> Unable to start activity
> ComponentInfo{graffit.main/graffit.main.GraffSearch}:
> android.view.InflateException: Binary XML file line #9: Error inflating
> class ListFragment
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.app.ActivityThread.access$1500(ActivityThread.java:124)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.os.Handler.dispatchMessage(Handler.java:99)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.os.Looper.loop(Looper.java:130)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.app.ActivityThread.main(ActivityThread.java:3806)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> java.lang.reflect.Method.invokeNative(Native Method)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> java.lang.reflect.Method.invoke(Method.java:507)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> dalvik.system.NativeStart.main(Native Method)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): Caused by:
> android.view.InflateException: Binary XML file line #9: Error inflating
> class ListFragment
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.view.LayoutInflater.inflate(LayoutInflater.java:408)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.view.LayoutInflater.inflate(LayoutInflater.java:320)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.view.LayoutInflater.inflate(LayoutInflater.java:276)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.support.v4.app.FragmentActivity.setContentView(FragmentActivity.java:421)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> graffit.main.GraffSearch.onCreate(GraffSearch.java:16)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): ... 11 more
>     03-18 03:38:49.363: E/AndroidRuntime(8385): Caused by:
> java.lang.ClassNotFoundException: android.view.ListFragment in loader
> dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/graffit.main-1.apk]
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> java.lang.ClassLoader.loadClass(ClassLoader.java:551)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> java.lang.ClassLoader.loadClass(ClassLoader.java:511)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.view.LayoutInflater.createView(LayoutInflater.java:471)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): at
> android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
>     03-18 03:38:49.363: E/AndroidRuntime(8385): ... 19 more
>     03-18 03:43:49.424: I/Process(8385): Sending signal. PID: 8385 SIG: 9
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 4.1 Available!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment