我在sqlite数据库表中有图像名称。迭代光标获取图像名称并尝试逐个获取图像进行显示。 TableLayouts,TableRow,ImageView以编程方式创建。读取一些图像后发生致命异常并且应用程序崩溃。给出任何解决问题的建议。
Cursor cursor = GlobalClass.db.getCursor("FBPMGPT as a,FBMRMMT as b", new String[] {"a.MenuGroup,a.Description,b.ItemCode,b.ItemName,b.ItemRate"},"a.MenuGroup=b.MenuGroup and b.RestaurantCode='" + GlobalClass.RESTAURANT_CODE + "'", "a.MenuGroup,b.ItemName"); cursor.moveToFirst(); TableLayout tablelayout = new TableLayout(thisActivity) if(!cursor.isAfterLast()) { do { TableRow tablerow = new TableRow(thisActivity); ////////////Image to item get here based on item code//////////////////// imageView = getItemImageView(thisActivity, thisContext, cursor.getString(2)); imageView.setPadding(10, 10, 10, 10); imageView.setTag(cursor.getString(2)); imageView.setBackgroundResource(R.drawable.border); tablerow.addView(imageView); tablelayout.addView(tablerow); } while (cursor.moveToNext()); cursor.close(); } public ImageView getItemImageView(Activity activity, Context context, String s) { String Foldername="ImageFolder" String s2=""; ImageView imageview; String s1 = Environment.getExternalStorageDirectory()+"/"+Foldername+"/"+s.trim().toString(); if (fileExists(s1+".JPG")) s2 = s1+".JPG".toString(); else if (fileExists(s1+".PNG")) s2 = s1+".PNG".toString(); else s2 = ""; imageview = new ImageView(context); if (!s2.equals("")) { Bitmap bitmap=BitmapFactory.decodeFile(s2); Bitmap bm=bm.createScaledBitmap(bitmap,100,100, true); imageview.setImageBitmap(bm); } else { imageview.setImageResource(R.drawable.noimagefound); imageview.setAdjustViewBounds(true); } imageview.setMaxWidth(GlobalClass.BUTTON_GLOBAL_ITEM_IMAGE_WIDTH); imageview.setMaxHeight(GlobalClass.BUTTON_GLOBAL_ITEM_IMAGE_HEIGHT); return imageview; }