3

CursorAdapterを拡張するクラスを作成しましたが、bindViewメソッドで問題が発生しています。

@Override
public void bindView(View v, Context context, Cursor c) {


    int colNum = c.getColumnIndex(VidCallDbAdapter.QRLINK);
    String colValue = c.getString(colNum);

    System.out.println("value>> " + colValue);

    TextView name_text = (TextView) v.findViewById(R.id.qr_url);

    name_text.setText(colValue);

}

この行で常にNullPointerExceptionが発生します

TextView name_text =(TextView)v.findViewById(R.id.qr_url);

xmlの1つでqr_urlを定義したので、奇妙です。

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

<TextView android:layout_height="wrap_content" 
          android:text=""   
          android:id="@+id/qr_url" 
          android:gravity="center_vertical" 
          android:layout_width="fill_parent" 
          android:textColor="#000000" 
          android:textSize="12sp">
</TextView>

</LinearLayout>  

コードで何かを見逃しましたか?それがNullPointerExceptionである理由ですか?前もって感謝します。

4

2 に答える 2

2

あなたがNullPointerExceptionこの列に入っているなら

TextView name_text = (TextView) v.findViewById(R.id.qr_url);

これはnullを意味しv、TextViewが見つからない場合はnull返さNullPointerExceptionれ、スローされます。

name_text.setText(colValue);

したがって、public View newView(...)が正しくオーバーライドされていることを確認してください。

newViewで返す必要があるものを編集します

return inflater.inflate(R.layout.<name of your xml>, parent, false);
于 2011-10-20T08:01:31.107 に答える
0

bindView()が NullPointerException をスローするという同様の問題がありました。setEmptyView()ListViewを呼び出して解決しました。

于 2014-02-15T00:24:59.843 に答える