Your content must have a ListView whose id attribute is ‘android.R.id.…

I have get Error in my listview Your content must have a ListView whose id attribute is ‘android.R.id.list’

03-04 17:53:12.558: E/AndroidRuntime(8469): FATAL EXCEPTION: main
    03-04 17:53:12.558: E/AndroidRuntime(8469): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.app.ListFragment.ensureList(ListFragment.java:344)
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.app.ListFragment.onViewCreated(ListFragment.java:145)
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1105)
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1461)
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
    03-04 17:53:12.558: E/AndroidRuntime(8469):     at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)

this xml with name timeline.xml


    

        
    

    

and this TimelineFragment.class

package app.jrupac.cleantwitter;

import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;

import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.User;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class TimelineFragment extends BaseListFragment {

    public final String TAG = Utils.TAG_BASE + this.getClass().getName();

    private static TimelineFragment mTimelineFragment = null;

    private View mView;
    private ListView mListView;
    private TweetData[] mUpdatedTweets = null;
    private TweetAdapter mAdapter = null;
    private Context mContext;
    private OAuth mOAuth;
    private TwitterAPI mTwitterAPI;

    public static TimelineFragment getInstance() {
        if (mTimelineFragment == null) {
            mTimelineFragment = new TimelineFragment();
        }

        return mTimelineFragment;
    }

    @Override
    public void onForceRefresh() {
         Log.i(TAG, "Getting updates for timeline");
         mTwitterAPI.getHomeTimeline(this);
    }

    @Override
    public void onParseCompleted(ResponseList statuses) {
        mUpdatedTweets = new TweetData[statuses.size()];
        for (int i = 0; i < mUpdatedTweets.length; i++) {
            TweetData t = new TweetData();
            Status s = statuses.get(i);
            User u = s.getUser();

            t.name = u.getName();
            t.username = "@" + u.getScreenName();
            t.text = s.getText();
            t.time = u.getCreatedAt();
            try {
                t.avatar_url = new URL(u.getProfileImageURL());
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            t.avatar = null;

            mUpdatedTweets[i] = t;
        }

        postResults(false);
    }

    private void postResults(boolean getFromDB) {
        mAdapter = new TweetAdapter(mContext, R.layout.timeline_listitem,
                mUpdatedTweets);
        mListView.setAdapter(mAdapter);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.timeline, container, false);
        mListView = (ListView) mView.findViewById(android.R.id.list);
        mListView.setEmptyView(mView.findViewById(android.R.id.empty));
        mContext = getActivity().getApplicationContext();
        mOAuth = OAuth.getInstance((BaseActivity) getActivity());
        mTwitterAPI = TwitterAPI.getInstance(mContext);

        if (mOAuth.isLoggedIn()) {
            Log.i(TAG, "Getting updates for timeline");
            mTwitterAPI.getHomeTimeline(this);
            return mView;
        } else {
            return inflater.inflate(R.layout.not_logged_in, container, false);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private class TweetAdapter extends ArrayAdapter {
        private TweetData[] mTweets;
        private LayoutInflater mInflater;
        private View mView;
        private SimpleDateFormat mSdf;
        private final String DATE_FORMAT = "hh:mm aa";

        public TweetAdapter(Context context, int textViewResourceId,
                TweetData[] objects) {
            super(context, textViewResourceId, objects);
            mTweets = objects;
            mInflater = LayoutInflater.from(context);
            mSdf = new SimpleDateFormat(DATE_FORMAT);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;

            if (convertView == null) {
                mView = mInflater.inflate(R.layout.timeline_listitem, null);

                holder = new ViewHolder();
                holder.name = (TextView) mView.findViewById(R.id.tweet_name);
                holder.username = (TextView) mView
                        .findViewById(R.id.tweet_username);
                holder.time = (TextView) mView.findViewById(R.id.tweet_time);
                holder.text = (TextView) mView.findViewById(R.id.tweet_text);
                holder.avatar = (ImageView) mView
                        .findViewById(R.id.tweet_avatar);
                mView.setTag(holder);
            } else {
                mView = convertView;
                holder = (ViewHolder) mView.getTag();
            }

            TweetData current = mTweets[position];

            holder.name.setText(Html.fromHtml(current.name));
            holder.username.setText(Html.fromHtml(current.username));
            holder.time.setText(mSdf.format(current.time));
            holder.text.setText(Html.fromHtml(current.text));

            if (current.avatar == null) {
                ThumbnailDownloader.fetchDrawable(current, holder.avatar);
            } else {
                holder.avatar.setImageDrawable(current.avatar);
            }

            return mView;
        }
    }
}

class ViewHolder {
    public TextView name;
    public TextView username;
    public TextView time;
    public TextView text;
    public ImageView avatar;
}

and this BaseListFragment.class

package app.jrupac.cleantwitter;

import twitter4j.ResponseList;
import twitter4j.Status;
import android.graphics.Bitmap;
import android.support.v4.app.ListFragment;
import android.view.View;

public class BaseListFragment extends ListFragment {

    public void onForceRefresh() {
        return;
    }

    public void onThumbnailDownload(Bitmap bmp, View v) {
        // Sub-classes should override this function to implement
        // functionality upon retrieval of images
        return;
    }

    public void onParseCompleted(ResponseList statuses) {
        // Sub-classes should override this function to implement
        // functionality upon retrieval of data
        return;
    }
}

NB : EDITED

i have check the xml, this is true format listview android:id=”@android:id/list
“, but why still error ? anybody help me ? sorry for my english

try doing sth like this

public class FragmentActivity extends ListFragment{

//your code.

}
Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » Your content must have a ListView whose id attribute is ‘android&period;R&period;id&period;…

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录