Reputation: 11
Why do eclipse itself imports android.R because when it does it gives me an error while using bitmaps and getting pictures from the drawable files from the res folder of my project. below is my code . The error comes in the line:
Bitmap tempBitmap = BitmapFactory.decodeResource(myContext.getResources(), R.drawable.card_back);
It says card_back cannot be resolved even when their is a png file in the drawable folder inside res . Also if i remove import android.R from the file it works perfectly fine , i am new to android any help is welcomed .
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import android.R;
import android.R.color;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.hardware.Camera.Size;
import android.view.MotionEvent;
import android.view.View;
import android.graphics.Color;;
@Override
public void onSizeChanged (int w, int h, int oldw, int oldh){
super.onSizeChanged(w, h, oldw, oldh);
screenW = w;
screenH = h;
Bitmap tempBitmap = BitmapFactory.decodeResource(myContext.getResources(), R.drawable.card_back);
scaledCardW = (int) (screenW/8);
scaledCardH = (int) (scaledCardW*1.28);
cardBack = Bitmap.createScaledBitmap(tempBitmap, scaledCardW, scaledCardH, false);
initCards();
dealCard();
drawCard(discardPile);
// initCards();
}
Upvotes: 0
Views: 67
Reputation: 8293
That happens because you are importing the android resources (android.R), not yours. If you want use any resource stayed in the res
folder, you must import nothing, because the auto-generate R.class scope is accesible from any class of your project.
Upvotes: 0
Reputation: 10288
You should usually import your project's own R
class, i.e., your.app.package.R
. The values you define under your project's res/ folder will be generated into that class. When you need to refer to the Android R
for a stock string or something, use its fully qualified name, e.g., android.R.string.yes
.
Upvotes: 1