Нулевое исключение - не знаю почему - PullRequest
0 голосов
/ 05 октября 2011

ну, я не понимаю, почему я получаю нулевое исключение в моем коде:

 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>

Чего мне не хватает?спасибо

1 Ответ

2 голосов
/ 05 октября 2011

Строка 182 - TextView t = (TextView) v.findViewById(R.id.TextView01); Идентификатор в вашем макете - @+id/textView1

Кажется, у вас есть TextView01 в других местах ваших ресурсов (что позволяет скомпилировать код), но не в пределах текущего макета.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...