2015-08-14 84 views
-2
的setText

我已經使用的setText很多次,但現在當過我嘗試做的setText我得到Android應用程序試圖做的TextView

顯示java.lang.NullPointerException時崩潰.widget.TextView.setText(java.lang.CharSequence中)」上的空對象引用

public View getView(int position, View conver, ViewGroup parent) { 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     if (convertView == null) { 

      convertView = inflater.inflate(R.layout.ac_layout, null); 
     } 
      ImageView icon = (ImageView) convertView.findViewById(R.id.venue_image); 
      icon.setImageResource(sportsMap.get(sportList.get(position).getId())); 
      TextView venueName = (TextView) convertView.findViewById(R.id.venue_name); 
      //Toast.makeText(context,venueList.get(position).getVenueName(),Toast.LENGTH_SHORT).show(); 
      venueName.setText(sportList.get(position).getDisplayName()); 
      TextView Place = (TextView)convertView.findViewById(R.id.place); 
      Place.setText("sad"); 

     return convertView; 
    } 

在這裏,在線路Place.setText發生錯誤( 「悲傷」);

我不會在其他地方發現錯誤,只有在那Place.setText(「sad」);我得到錯誤。

我已經在我的xml中聲明瞭TextView。我只是不知道爲什麼我的應用程序崩潰。

我真的期待有幫助的答案。

+0

你可以請張貼logcat的太.. – Lal

+2

另外,如果可以的話,請張貼'sport_listitem.xml'文件太.. – Lal

+0

給我一秒鐘PLZ – penta

回答

0

你是不是誇大了正確的xml文件,你沒有與ID place一個TextView在sport_listitem.xml

0

看起來像你的佈局文件會人爲增加sport_listitem.xml沒有TextViewandroid:id="@+id/place"

+2

不想爭論,但例外情況很明顯... – pelotasplus

相關問題