开发者

How to display gestures from the library as a bitmap?

开发者 https://www.devze.com 2023-02-18 00:43 出处:网络
I need to display the gesture library as a bitmap images. The code below is what I have, however it doesnt seem to work. I am getting an error on Logcat every time I run the program.

I need to display the gesture library as a bitmap images. The code below is what I have, however it doesnt seem to work. I am getting an error on Logcat every time I run the program.

sStore = GestureLibraries.fromRawResource(this, R.raw.gestures_alph);
    int i = 0;
    for (String name : sStore.getGestureEntries())
    {  
            for (Gesture gesture : sStore.getGestures(name))
            {
                Bitmap bitmap = gesture.toBitmap(mThumbnailSize, mThumbnailSize, mThumbnailInset, mPathColor);
                theList.add(i,bitmap);
                i++;
            }
    }

    int rand = (int)(Math.random()*theList.size());
    Bitmap element = theList.get(rand);
    imagetemp.setImageBitmap(element);
    gestures.addView(imagetemp);

}

The error I get is shown below, It says that there is nothing in the arraylist, so it is probably the for loop.

ERROR/AndroidRuntime(8258): Uncaught handler: thread main exiting due to uncaught exception ERROR/AndroidRuntime(8258): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.menu.sample/com.menu.sample.ImageTest}: java.lang.IndexOutOfBoundsException: Invalid location 0, size is 0 java.util.ArrayList.get(ArrayList.java:341)

Error Fixed The Library had to be loaded first.

if (sStore.load()){
     for (String name : sStore.getGestureEntries())      {
         for (Gesture g开发者_C百科esture : sStore.getGestures(name))

                {


The error basically is trying to tell you that the list of bitmaps is empty. So, first of all, check the size of the list:

if( theList.size() > 0 ){
    int rand = (int)(Math.random()*theList.size());
    Bitmap element = theList.get(rand);
    imagetemp.setImageBitmap(element);
    gestures.addView(imagetemp);
}

And debug the first part of your code to see why your list is not being populated with the bitmaps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号