package com.lala.image;
import com.lala.ContextStore;
import android.R;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
public class Stationary implements Image{
View v;
Context context;
String image;
Bitmap img;
float x;
float y;
public Stationary(Context context, String image) {
// TODO Auto-generated constructor stub
this.image = image;
this.context = context;
this.setImage(image);
}
public void setImage(String image) {
// TODO Auto-generated method stub
if(image=="bdfs"){
this.img = BitmapFactory.decodeResource(context.getResources(), R.id.icon);
}
else if(image=="ssdfsdf"){
this.img = BitmapFactory.decodeResource(context.getResources(), R.id.icon);
}
else if(image=="asfdsdf"){
this.img = BitmapFactory.decodeResource(context.getResources(), R.id.icon);
}
else{
this.img = BitmapFactory.decodeResource(context.getResources(), R.id.icon);
}
}
public Bitmap getImage(){
return img;
}
public float getX() {
// TODO Auto-generated method stub
return this.x;
}
public float getY() {
// TODO Auto-generated method stub
return this.y;
}
public void setX(float x) {
// TODO Auto-generated method stub
this.x = x;
}
public void setY(float y) {
// TODO Auto-generated method stub
this.y = y;
}
}
I am not sure how to use context and resources in a class when it is called from another activity.
I am getting an error message when the context or resources are called.
Any code to assist would be very welcome.
Thanks for your time
It looks like the problem is not with the context but with the way you’re calling
BitmapFactory.decodeResource(). I see you’re passing inR.id.iconwhich is an ID of an element in a layout. You need to pass in a reference to an image. Something likeR.drawable.your_bitmapinstead.