I have two classes, Class A called Apply and Class B called Option
I want class A to get a resource from class B, but I’m getting error
the error I’m getting
Cannot make a static reference to the non-static method getResources() from the type ContextWrapper
the function on class A
public static void applyBitmap(int resourceID) {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inScaled = true;
opt.inPurgeable = true;
opt.inInputShareable = true;
Bitmap brightBitmap = BitmapFactory.decodeResource(getResources(), resourceID, opt);
brightBitmap = Bitmap.createScaledBitmap(brightBitmap, 100, 100, false);
MyBitmap = brightBitmap;
}
and example of a resource button in class B
// the 34th button
Button tf = (Button) findViewById(R.id.tFour);
tf.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Apply.applyBitmap(R.drawable.tFour);
}
});
note*: before when the function was on class B in was working great, but know I think I need to static the resource but how ? I don’t know
I tried Option.getResources() but it didn’t work, it gives an error
You are accessing
getResources()without a reference to aContext. Because this is a static method, you can only access other static methods within that class without providing a reference.Instead, you must pass the
Contextas an argument:Then, you must reference it for
getResources():