我需要將手勢庫顯示爲位圖圖像。下面的代碼是我的,但它似乎沒有工作。每次運行程序時,我都會在Logcat上發生錯誤。如何將庫中的手勢顯示爲位圖?
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);
}
我得到的錯誤如下所示,它表示在arraylist中沒有任何東西,所以它可能是for循環。
ERROR/AndroidRuntime(8258):未捕獲的處理程序:線程退出主要由於未捕獲的異常 ERROR/AndroidRuntime(8258):了java.lang.RuntimeException:無法啓動活動ComponentInfo {com.menu.sample/COM。 menu.sample.ImageTest}:java.lang.IndexOutOfBoundsException:無效位置0,大小爲0 java.util.ArrayList.get(ArrayList.java:341)
錯誤修正 圖書館必須是首先加載。
if (sStore.load()){
for (String name : sStore.getGestureEntries()) {
for (Gesture gesture : sStore.getGestures(name))
{
我修正了錯誤,我沒有加載庫。 – Navigatron 2011-03-21 19:59:30