2010-09-28 6 views
0

Я пытаюсь создать представление списка, но я получаю следующую ошибку. Может кто-нибудь сказать мне, что не так с моим кодом.ListView с использованием макета Infleter в android

поэтому, пожалуйста, помогите мне.

09-28 10: 52: 28,918: ERROR/AndroidRuntime (383): Вызванный: java.lang.RuntimeException: Ваше содержание должно иметь ListView, идентификатор атрибута 'android.R.id.list' 09 -28 10: 52: 28.918: ОШИБКА/AndroidRuntime (383): at android.app.ListActivity.onContentChanged (ListActivity.java:245) 09-28 10: 52: 28.918: ERROR/AndroidRuntime (383): at com. android.internal.policy.impl.PhoneWindow.setContentView (PhoneWindow.java:201) 09-28 10: 52: 28.918: ОШИБКА/AndroidRuntime (383): at android.app.Activity.setContentView (Activity.java:1647) 09-28 10: 52: 28.918: ОШИБКА/AndroidRuntime (383): at com.unundoinc.FaceBook.Activity.NewsFeedActivity.onCreate (NewsFeedActivity.java:51) 09-28 10: 52: 28.918: ERROR/AndroidRuntime (383): at android.app.In strumentation.callActivityOnCreate (Instrumentation.java:1047) 09-28 10: 52: 28,918: ОШИБКА/AndroidRuntime (383): в android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2627)

* * * **ЭТО МОЯ XML-файл, который СОДЕРЖАТЬ LIST VIEW ** * ** * *

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/newsfeedactivity" android:orientation="horizontal" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 

    <ListView android:id="@+id/list" android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    </ListView> 

</LinearLayout> 

** * ** * ***ЭТО МОЯ .Java FILE ** * ** * ** * ** * ** *

public class NewsFeedActivity extends ListActivity 
{ 
    public ArrayList<UserDetail> mData ; 
    private ListView feedbookListView; 


    OAuth oauth = new OAuth(); 
    public static final String TAG = "NewsFeedActivity"; 
    public static final String FaceBookURL = "http://graph.facebook.com/"; 

    private ListAdapter objListAdapter; 

    private TextView textMessage = null; 
    private ImageView backThumbnail = null; 
    private ImageView urlThumbnail = null; 

    private String access_token = ""; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstance) 
    { 
     super.onCreate(savedInstance); 
     access_token = getIntent().getExtras().getString("ACCESS_TOKEN"); 
     setContentView(R.layout.newsfeedactivity); 

     // Setting Context of the ThumbnailManager 
     ThumbnailManager.context = this; 

     feedbookListView = (ListView) findViewById(R.id.list); 
     textMessage = (TextView)findViewById(R.id.facebook_text); 


     mData = new ArrayList<UserDetail>(); 
     this.objListAdapter = new ListAdapter(this, R.layout.newsfeedactivitycell, mData); 
     setListAdapter(objListAdapter); 

     onComplete(); 

    } 
    ////////////////////////////////////////////////////////////////////////////// 
    public void onComplete() 
    {  
     Bundle parameters = new Bundle(); 
     String response = null; 

     /*Inserts a String value into the mapping of this Bundle, 
      replacing any existing value for the given key. Either key or value may be null. 
     */ 
     parameters.putString("access_token", access_token); 
     //parameters.putString("method", "platform/posts"); 

     Log.v(TAG, "PARAMETERS :: "+parameters); 
     try 
     { 
      response = oauth.request("platform/posts" , parameters); 
      android.util.Log.v(TAG, "RESPONSE :: " + response); 
     } 
     catch (MalformedURLException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     catch (IOException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     /** 
     * To parse the FeedBook using JSON parsing 
     */ 


     try 
     { 
      JSONObject temp = new JSONObject(response); 
      JSONArray arrayOfJsonObjs = temp.getJSONArray("data"); 
      Log.v(TAG, "ARRAY SIZE :: " + arrayOfJsonObjs.length()); 
      UserDetail objUserDetail = new UserDetail(); 
      for(int i = 0; i< arrayOfJsonObjs.length(); i++) 
      { 
       try 
       { 
        JSONObject objFromArr = arrayOfJsonObjs.getJSONObject(i); 
        JSONObject objFromObj = objFromArr.getJSONObject("from"); 

        if(objFromObj.has("id") == true) 
        { 
         objUserDetail.setUserId(objFromObj.getString("id")); 
        } 
        else 
        { 
         objUserDetail.setUserId(""); 
        } 

        if(objFromObj.has("name") == true) 
        { 
         objUserDetail.setUserName(objFromObj.getString("name")); 
        } 
        else 
        { 
         objUserDetail.setUserName(""); 
        } 

        if(objFromArr.has("picture") == true) 
        { 
         objUserDetail.setUserStatusImage(objFromArr.getString("picture")); 
        } 
        else 
        { 
         objUserDetail.setUserStatusImage(""); 
        } 

        if(objFromArr.has("caption") == true) 
        { 
         objUserDetail.setUserStatus(objFromArr.getString("caption")); 
        } 
        else 
        { 
         objUserDetail.setUserStatus(""); 
        } 

        objUserDetail.setUserProfileImageUrl 
        (FaceBookURL+ 
          objUserDetail.getUserId()+ 
          "/picture" 
        ); 

        Log.v 
        (
          TAG, 
          //" Array Of Json Objects : [" + i+"] is::" + arrayOfJsonObjs.getJSONObject(i) 
          //"ICON URL ["+i+"] is ::"+objFromArr.getString("icon") 
          "OBJECT ["+i+"]"+ "\n"+ 
          "Picture URL is ::"+objUserDetail.getUserStatusImage() + "\n"+ 
          "This is your id :: "+objUserDetail.getUserId()+ "\n"+ 
          "This is your name ::"+objUserDetail.getUserName()+ "\n"+ 
          "This is Status Message ::"+objUserDetail.getUserStatus()+ "\n"+ 
          "Profile picture image URL is ::"+objUserDetail.getUserProfileImageUrl() 

        ); 
       } 
       catch (JSONException e) 
       { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
     } 

     catch (JSONException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

    } 

    //////////////////////////////////////////////////////////////////////////// 

    public class ListAdapter extends ArrayAdapter<UserDetail> 
    { 
     LayoutInflater inflater; 
     private ThumbnailManager objThumbnailManager = new ThumbnailManager(); 
     private ArrayList<UserDetail> items; 

     //private Bitmap back = null; 
     //private Bitmap type = null; 


     public ListAdapter(Activity context, int textViewResourceId,ArrayList<UserDetail> items) 
     { 
      super(context, textViewResourceId, items); 
      this.items = items; 
     } 



     @Override 
     public View getView(int position, View convertView, ViewGroup parent) 
     {   
      //View row = inflater.inflate(R.layout.newsfeedactivitycell, null); 
      View objView= convertView; 
      if (objView == null) 
      { 
       LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       objView = vi.inflate(R.layout.newsfeedactivitycell, null); 
      } 

      UserDetail objUserDetail = items.get(position); 
      if (objUserDetail != null) 
      { 

       textMessage = (TextView)findViewById(R.id.facebook_text); 

       if(textMessage != null) 
       { 
        textMessage.setText("StatusMessage: "+ objUserDetail.getUserStatus()); 
       } 
      } 

      return objView; 

      //   textMessage = (TextView) row.findViewById(R.id.facebook_text); //id    
      //   //backThumbnail = (ImageView) row.findViewById(R.id.facebook_thumbnail); //drawable 
      //   textMessage.setText(objListAdapter.getItem(position).getUserStatus());   



     }  

    } 
} 

ответ

2

Измените идентификатор своего списка на android:id="@android:id/list" и он должен исключить исключение.

Смежные вопросы