2012-02-19 62 views
0

這裏是我的腳本(部分代碼)的代碼:錯誤使用setBackgroundResource()時

r1c1text.setOnClickListener(new OnClickListener() { 
     public void onClick(View v){ 

      v.setBackgroundColor(0xff000000); 
      v.setBackgroundResource(R.id.xImg); 
      Toast.makeText(Connect.this, "" + v, Toast.LENGTH_SHORT).show(); 
     } 
    }); 

這裏是XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="#ffffff" 
    android:layout_width="fill_parent" 
    android:layout_height="80dip" 
    android:orientation="horizontal" 
    android:layout_below="@+id/connectImg" 
> 
<TextView android:id="@+id/r1c1text" 
      android:layout_width="80dip" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dip" 
      android:textColor="#000000" 
      android:text="@string/class1"/> 
<TextView android:id="@+id/r1c2text" 
      android:layout_width="80dip" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/r1c1text" 
      android:layout_marginLeft="20dip" 
      android:textColor="#000000" 
      android:text="@string/machine"/> 
<TextView android:id="@+id/r1c3text" 
      android:layout_width="80dip" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/r1c2text" 
      android:layout_marginLeft="20dip" 
      android:textColor="#000000" 
      android:text="@string/ceiling"/> 
</RelativeLayout> 

Eclipse不給我v.setBackgroundResource(R.id.xImg);一個錯誤,但機器人說"Force close"。我究竟做錯了什麼?

+1

後logcat的錯誤消息。 – kosa 2012-02-19 20:06:45

回答

1

呦文件名中帶一個大寫字母,使用所有小寫ximg而不是xImg

相關問題