5

I am trying to run "BitmapFun" official example but getting the following errors:

1)Cannot resolve symbol KITKAT 2) Cannot resolve method getAllocationByteCount()

Any help ?

My AndroidManifest.xml :

<uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="19" />

and here is the code :

 @TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (Utils.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}
Vishwas
  • 1,533
  • 2
  • 19
  • 40

2 Answers2

19

You'll need to set the build SDK version to 19 (4.4) or higher to have API level 19 symbols available while compiling.

First, use the SDK Manager to download API 19 if you don't have it yet.

Then, configure your project to use API 19:

  • In Android Studio: File -> Project Structure -> General Settings -> Project SDK.

  • In Eclipse ADT: Project Properties -> Android -> Project Build Target

laalto
  • 150,114
  • 66
  • 286
  • 303
  • so, does that mean, i will have to download the SDK again ? I am not able to figure out which api version of sdk i am using. – Vishwas Dec 04 '13 at 12:28
  • ok, i think from here : http://developer.android.com/tools/help/sdk-manager.html Thanks. – Vishwas Dec 04 '13 at 12:31
2

the method bitmap.getAllocationByteCount() was introduced in API level 19.
if your project build target is less than API 19, it will give error.

try this...

1) select your project root folder and right click

2) go to properties -> android

3) select API 19 as your project build target and clean your project

Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43