开发者

Error with a xml view

I keep getting this error

07-14 23:53:03.653: ERROR/AndroidRuntime(14995): java.lang.NullPointerException
07-14 23:53:03.653: ERROR/AndroidRuntime(14995):     at com.fttech.organizeit.meeting_list$meetingHolder.populateFrom(meeting_list.java:110)
07-14 23:53:03.653: ERROR/AndroidRuntime(14995):     at com.fttech.organizeit.meeting_list$meetingAdapter.bindView(mee开发者_如何学JAVAting_list.java:82)
07-14 23:53:03.653: ERROR/AndroidRuntime(14995):     at    android.widget.CursorAdapter.getView(CursorAdapter.java:186)
07-14 23:53:03.653: ERROR/AndroidRuntime(14995):     at android.widget.AbsListView.obtainView(AbsListView.java:1315)

It works when i run it on a xlarg screen. but when i run it on a regular layout it keeps force closing at this line

meetingHolder(View row){
        mtitle=(TextView)row.findViewById(R.id.mtitle);
        maddress = (TextView)row.findViewById(R.id.address);
        Icon = (ImageView)row.findViewById(R.id.Micon);

    }
    void populateFrom(Cursor c, meetingHelper helper){
        mtitle.setText(helper.getMettingTitle(c));
        maddress.setText(helper.getAddress(c));

        if(helper.getType(c).equals("completed")){
            Icon.setImageResource(R.drawable.completed);

        }

Here is my xml for it

<?xml version="1.0" encoding="utf-8"?>
   <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
android:padding="4dip">
<ImageView
    android:id="@+id/Micon"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentTop = "true"
    android:layout_alignParentBottom = "true"
    android:layout_marginRight="4dip"
    />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
        android:textColor="#15317E"
            android:id="@+id/mtitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:textStyle="bold"
            android:maxLines="1"
            android:ellipsize="end"
            />

            <TextView
            android:textColor="#15317E"
            android:id="@+id/address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="1"
            android:textSize="16dip"
            android:ellipsize="middle"/>




        </LinearLayout>
    </LinearLayout>

I have no idea why this has started happening all of a sudden but its very annoying.

}
public String getType(Cursor c){
    return(c.getString(7));
}


try fill_parent instead of match_parent


helper.getType(c) must be returning null. Where is the code for meetingHelper? Are the underlying Cursor instances on the regular and on the xlarge (which I'm assuming are 2 different databases) identical? You must have a null coming back from the Cursor for whichever row, or your getType method is doing something wrong.


Your cursor is null - this happens if there are no results returned from the database query.

You should check if the cursor is null before you operate on it. Code change below:

meetingHolder(View row){
    mtitle=(TextView)row.findViewById(R.id.mtitle);
    maddress = (TextView)row.findViewById(R.id.address);
    Icon = (ImageView)row.findViewById(R.id.Micon);

}
void populateFrom(Cursor c, meetingHelper helper){
    if (c != null) {
         mtitle.setText(helper.getMettingTitle(c));
         maddress.setText(helper.getAddress(c));

         if(helper.getType(c).equals("completed")){
             Icon.setImageResource(R.drawable.completed);

         }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜