user10935001
user10935001

Reputation:

How to change a photo?

I am trying to change photos in android studio by clicking on my button. When I put code for changing the photo in my MainActivity.java I keep getting this type of error messages and it says : Cannot resolve symbol "image"

image.setImageResource(R.drawable.xxx);

I am watching Udemy course for android development and I have done everything same like the professor on that video.

I have tried to restart android studio. I have tried to make new project. I have tried to clear invalidate caches and restart.

public void changeImage(View view)
{
    ImageView bitcoin = findViewById(R.id.bitcoin);
    image.setImageResource(R.drawable.xxx);


}

I hope there is actual error with android studio,because code is clone of the video that I am watching.

Upvotes: 0

Views: 147

Answers (3)

Sagar Poshiya
Sagar Poshiya

Reputation: 134

Set Your Code Like this

ImageView image = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);

Upvotes: 1

Reva
Reva

Reputation: 59

You are binding your layout's ImageView in Java file with bitcoin variable and you are trying to set an image on an unknown variable 'image'(maybe it's not defined in the class). So you have to set as below.

ImageView bitcoin = findViewById(R.id.bitcoin); bitcoin.setImageResource(R.drawable.xxx);

Upvotes: 1

Freny Christian
Freny Christian

Reputation: 116

change your this line

image.setImageResource(R.drawable.xxx)

to this one:

bitcoin.setImageResource(R.drawable.xxx)

Upvotes: 0

Related Questions