I am able to get the data from the sqlite database. However, when my image url is null, it prevents my other things from getting displayed.
try{
name.setText(nameString);
school.setText(schoolString);
psupervisor.setText(info.getPsupervisor());
pdate.setText(info.getPdate());
a.setChecked(Boolean.parseBoolean(info.getPtick1()));
b.setChecked(Boolean.parseBoolean(info.getPtick2()));
c.setChecked(Boolean.parseBoolean(info.getPtick3()));
pcomment1.setText(info.getPcomment1());
psignature1.setImageBitmap(resizeSignatureBitmap(info.getPsignature1()));
pcomment2.setText(info.getPcomment2());
psignature2.setImageBitmap(resizeSignatureBitmap(info.getPsignature2()));
pdate2.setText(info.getPdate2());
d.setChecked(Boolean.parseBoolean(info.getPtick4()));
e.setChecked(Boolean.parseBoolean(info.getPtick5()));
f.setChecked(Boolean.parseBoolean(info.getPtick6()));
pcomment3.setText(info.getPcomment3());
psignature3.setImageBitmap(resizeSignatureBitmap(info.getPsignature3()));
pcomment4.setText(info.getPcomment4());
psignature4.setImageBitmap(resizeSignatureBitmap(info.getPsignature4()));
Log.d("PREPOST: ", log2);
db.close();
}
catch(Exception ex){}
}
For example if psignature2 is null, the items from pdate2 to pcomment4 would not get displayed. Didn’t crash due to the try-catch therefore I discovered the cause of error late
My method for adjustment of bitmap resolution:
public Bitmap resizeSignatureBitmap(String imagePath){
BitmapFactory.Options options = new BitmapFactory.Options();
InputStream is = null;
try {
is = new FileInputStream(imagePath);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BitmapFactory.decodeStream(is,null,options);
try {
is.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
is = new FileInputStream(imagePath);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// here w and h are the desired width and height
options.inSampleSize = Math.max(options.outWidth/w, options.outHeight/h);
// bitmap is the resized bitmap
Bitmap bitmap = BitmapFactory.decodeStream(is,null,options);
is=null;
return bitmap;
}
Therefore, can anyone suggest any methods that I can do so that even if there is a null image url, it would not prevent the display of other image? Thanks!
In
resizeSignatureBitmapyou can apply a check at the end to check weather thebitmapto be returned isnullor not. In case itsnullyou can return some default bitmap.Or you can simply set images in separate
try catch blocks.