Android : Android: cannot resolve symbol "setImageResource"

on Saturday, March 21, 2015


I am trying to change the image for an ImageButton in my Java code, but I keep getting an error message "cannot resolve symbol "setImageResource".


The ImageButton is defined in my XML as follow:



<ImageButton
android:id="@+id/button_ir2"
android:layout_width="60dp"
android:layout_height="50dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="@android:color/white"
android:src="@drawable/img1"
android:scaleType="fitCenter"/>


And in my Java code:



final View vz=findViewById(R.id.button_ir2);
ImageButton aButton = (ImageButton)vz;
aButton.setImageResource(R.drawable.img2);


I think I am typecasting this correctly, but maybe not. Spent almost a day on this, any help will be greatly appreciated.


0 comments:

Post a Comment