2011-07-15 36 views
0

我不斷收到此錯誤錯誤與XML視圖

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(meeting_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) 

它的工作原理,當我一個xlarg屏幕上運行它。但是當我在常規佈局運行它保持力最終收於該線

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); 

     } 

這裏是我的xml它

<?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> 

我不知道爲什麼,這已開始發生突然的,但它非常煩人。

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

你從哪裏得到圖標 – Rasel

+0

剛更新了完整的代碼。 – yoshi24

回答

1

嘗試FILL_PARENT代替match_parent

+0

什麼部分雖然? – yoshi24

+0

在你所有視圖的xml文件中 – Rasel

+0

沒有,沒有工作 – yoshi24

0

helper.getType(c)必須返回null。 meetingHelper的代碼在哪裏?常規和xlarge上的底層Cursor實例(我假設它們是2個不同的數據庫)是否相同?您無論從哪一行開始都必須從遊標返回null,否則您的方法會出錯。

+0

沒有它的全部1個數據庫。當我在平板電腦上運行它時,它可以工作。當我在我的小屏幕手機上運行它時,forcec關閉,當我到達上面的列表 – yoshi24

+0

兩個數據庫中的數據是完全相同的嗎? – Femi

+0

我只有一個數據庫。對於每種屏幕尺寸,我都有兩種不同的佈局xml。它在layout-xlarge-land和portrait上運行。但是在常規佈局上它會關閉 – yoshi24

0

你的光標爲空 - 這種情況如果沒有從數據庫查詢返回的結果。

在對其進行操作之前,您應該檢查遊標是否爲空。代碼更改如下:

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

這仍然沒有工作。也許它的一些事情正在與手機上的調試 – yoshi24

+0

當我通過電子郵件發送自己的apk的工作。當我在手機上調試時出現錯誤。儘管感謝您的回覆。 – yoshi24