murli
murli

Reputation: 1561

Error when using setBackgroundResource()

Here is the code of my script (partial code):

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

Here is the 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 does not give me an error on v.setBackgroundResource(R.id.xImg); but the android says "Force close". What am I doing wrong?

Upvotes: 0

Views: 539

Answers (1)

Bill Gary
Bill Gary

Reputation: 3005

Yo have a capital letter in the filename, use all lower case ximg instead of xImg

Upvotes: 1

Related Questions