You are trying to put a Drawable
in your ImageButton
variable. That's not the correct way as you might have already guessed by the name of the method: findViewBy**Id**()
.
You'll need to pass Android the ID
of your view so that it is able to retrieve it from the xml
(Well, not from the xml, but you get the point). Altough you didn't post the logcat error output I would assume that your program died with a NullPointerException
That is because if findViewById()
does not find a View
for the given id it will return null
as you can read here. Your program will then die at the .setOnClickListener()
line because you invoke a method call on a null object.
So to make a long story short: Edit this line:
lock1 = (ImageButton) findViewById(R.drawable.btn_unlocked);
to look like this:
lock1 = (ImageButton) findViewById(R.id.imageButton1);