我有一个非常奇怪的错误。它只发生在模拟器中。我在多款Android手机和Acer平板电脑上测试过它,它在那里效果不错。Android应用程序崩溃,我不知道为什么
我的程序有一个循环,在位图中加载到Bitmap[] bitCards
。阵列由bitCards = new Bitmap[14]
设置为14个元素。
现在,循环12次把一个位图到数组如下:
bitCards[i] = BitmapFactory.decodeStream(inputStream);
,在i = 8,崩溃于本声明。
如果我
bitCards[0] = BitmapFactory.decodeStream(inputStream);
更换它不会崩溃,我想也许不知何故没等我,让下面的
bitCards[8]=BitmapFactory.decodeStream(inputStream); // Still did not crash.
唯一的感觉是数组不够大当我有
bitCards[i] = BitmapFactory.decodeStream(inputStream);
它是旧的记忆和放入一个新的对象,因此只有我创建一个对象的mory,但是......异常不会消失,我不应该得到某种错误吗?
这里是我的全码:
void Shuffle()
{
Random generator;
generator = new Random();
int[] iCardsUsed;
iCardsUsed = new int[55];
for(int i=0;i<55;i++)
iCardsUsed[i]=0;
try {
bitCards = new Bitmap[14];
iCards = new int[14];
iTurnOver = new int[14];
for (int i = 0; i < 12; i++)
{
iTurnOver[i]=0;
int cardId;
do {
cardId = generator.nextInt(50);
} while(iCardsUsed[cardId] ==1);
iCardsUsed[cardId] =1;
iCards[i]=cardId;
iCards[i]=i;
String fName=new String("card");
fName+=Integer.toString(iCards[i]+1);
fName+=".jpg";
AssetManager assetManager= ctx.getAssets();
InputStream inputStream;
inputStream = assetManager.open(fName);
// this is where it crashes
bitCards[i]=BitmapFactory.decodeStream(inputStream);
inputStream.close();
}
} catch(IOException e)
{
gi++;
}
// update screen
invalidate();
}
你能提供错误信息吗? –
请提供logcat信息。 – rahul