空异常 - 不知道为什么



好吧,我不明白为什么我得到一个空异常在我的代码:

 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) {
                bt.setText("Data: " + o.getDate().toString());
                }
            if(t != null){
                t.setText(o.getLink().toString());
            }
            }

        return v;
    }
}

我的目录上写着:

 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)

第182行是:

 TextView t = (TextView) v.findViewById(R.id.TextView01);

我在我的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>

我错过了什么?由于

第182行是TextView t = (TextView) v.findViewById(R.id.TextView01);布局中的id是@+id/textView1

似乎你有TextView01在你的资源的其他地方(允许代码编译),但不是在当前布局。

最新更新