well i don't understand why i'm getting a Null Exception in my code :
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.lista_comunidade, null);
}
Message o = items.get(position);
if (o != null) {
TextView tt = (TextView) v.findViewById(R.id.result_name);
TextView t = (TextView) v.findViewById(R.id.TextView01);
TextView bt = (TextView) v.findViewById(R.id.result_second_line);
//bt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 10);
t.setTextSize(TypedValue.COMPLEX_UNIT_PX, 10);
bt.setTextColor(-1);
tt.setTextColor(-1);
tt.setTextColor(-1);
ImageView iv = (ImageView) v.findViewById(R.id.result_icon);
iv.setImageResource(R.id.result_icon);
if (tt != null) {
tt.setText(o.getTitle());
}
if (bt != null) {
开发者_Go百科 bt.setText("Data: " + o.getDate().toString());
}
if(t != null){
t.setText(o.getLink().toString());
}
}
return v;
}
}
My catlog says that :
E/AndroidRuntime( 757): FATAL EXCEPTION: main
E/AndroidRuntime( 757): java.lang.NullPointerException
E/AndroidRuntime( 757): at com.warriorpoint.androidxmlsimple.MessageList
$SiteAdapter.getView(MessageList.java:182)
Line 182 is :
TextView t = (TextView) v.findViewById(R.id.TextView01);
And i have this in my xml :
<TextView android:text="@string/Text" android:layout_width="wrap_content" android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_alignParentBottom="true"></TextView>
What i'm missing? thanks
Line 182 is TextView t = (TextView) v.findViewById(R.id.TextView01);
The id in your layout is @+id/textView1
It seems that you have TextView01 elsewhere in your resources (allowing the code to compile), but not within the current layout.
精彩评论