user4666
user4666

Reputation: 73

I get a crash using Palette.From(bitmap).Generate(), how do I use correctly?

I am trying to generate colors to a palette on Android (Eclipse IDE). After running there is a freeze-crash on handset. Apparently i am not using the API correctly, but on search there is very little information on how to use palette.From(bitmap).Generate(); I have this code

import android.support.v7.graphics.Palette;
import android.support.v7.graphics.Palette.PaletteAsyncListener;
import android.support.v7.graphics.Palette.Builder;
....

int vibrant, vibrantLight, vibrantDark, muted, mutedLight, mutedDark;
public Palette palette;

void decodeColors2(){
    ....
    myBitmap = Bitmap.createScaledBitmap(bm, rWidth, rHeight, false); 

    palette = Palette.from(myBitmap).generate();


    vibrant = palette.getVibrantColor(0x000000);
    vibrantLight = palette.getLightVibrantColor(0x000000);
    vibrantDark = palette.getDarkVibrantColor(0x000000);
    muted = palette.getMutedColor(0x000000);
    mutedLight = palette.getLightMutedColor(0x000000);
    mutedDark = palette.getDarkMutedColor(0x000000);

}

Please can anyone let me know what i am doing wrong and how to correct my code to get a full run rather than a crash.

Also how do I use Palette.Builder(bitmap, number)? EDIT: crash log:

11-07 19:00:33.135: E/AndroidRuntime(31684): FATAL EXCEPTION: main
11-07 19:00:33.135: E/AndroidRuntime(31684): java.lang.NoClassDefFoundError: android.support.v7.graphics.Palette
11-07 19:00:33.135: E/AndroidRuntime(31684):    at com.example.liveideas.Liveideas.decodeColors2(Liveideas.java:699)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at com.example.liveideas.Liveideas$3.onPictureTaken(Liveideas.java:264)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at android.hardware.Camera$EventHandler.handleMessage(Camera.java:823)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at android.os.Looper.loop(Looper.java:137)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at android.app.ActivityThread.main(ActivityThread.java:4921)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at java.lang.reflect.Method.invokeNative(Native Method)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at java.lang.reflect.Method.invoke(Method.java:511)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
11-07 19:00:33.135: E/AndroidRuntime(31684):    at dalvik.system.NativeStart.main(Native Method)
11-07 19:02:04.585: W/Sensors(31684): sensorservice died [0x4d9e3660]
11-07 19:02:04.605: I/Process(31684): Sending signal. PID: 31684 SIG: 9
11-07 19:02:04.605: E/AndroidRuntime(31684): Error reporting crash
11-07 19:02:04.605: E/AndroidRuntime(31684): android.os.DeadObjectException
11-07 19:02:04.605: E/AndroidRuntime(31684):    at android.os.BinderProxy.transact(Native Method)
11-07 19:02:04.605: E/AndroidRuntime(31684):    at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:3305)
11-07 19:02:04.605: E/AndroidRuntime(31684):    at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:121)
11-07 19:02:04.605: E/AndroidRuntime(31684):    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
11-07 19:02:04.605: E/AndroidRuntime(31684):    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
11-07 19:02:04.605: E/AndroidRuntime(31684):    at dalvik.system.NativeStart.main(Native Method)

Thanks

Upvotes: 1

Views: 353

Answers (1)

yshahak
yshahak

Reputation: 5096

You probably didn't defined the support library properly. according to the docs:

To add a Support Library without resources to your application project:

Using Eclipse

Make sure you have downloaded the Android Support Library using the SDK Manager. Create a libs/ directory in the root of your application project. Copy the JAR file from your Android SDK installation directory (e.g., /extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory. Right click the JAR file and select Build Path > Add to Build Path.

In your case you need android-support-v7

Upvotes: 1

Related Questions