Guest User

Untitled

a guest
Oct 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. my code i got error as null pointer exception
  2.  
  3. public class CatListAdapter extends ArrayAdapter {
  4. ArrayList <String> alNames;
  5. ArrayList <String> alImages;
  6. ArrayList <String> alId;
  7. private Activity context;
  8. float cornerRadius = 50.0f;
  9. ImageView imageFlag;
  10.  
  11. public CatListAdapter(Activity context,ArrayList <String> alNames, ArrayList <String> alImages, ArrayList <String> alId) {
  12. super(context, R.layout.category_list, alNames);
  13. this.context = context;
  14. this.alNames = alNames;
  15. this.alImages = alImages;
  16. this.alId = alId;
  17.  
  18. }
  19.  
  20. @Override
  21. public View getView(int position, View convertView, ViewGroup parent) {
  22. View row=convertView;
  23. LayoutInflater inflater = context.getLayoutInflater();
  24. if(convertView==null)
  25. row = inflater.inflate(R.layout.category_list, null, true);
  26. TextView textViewCountry = (TextView) row.findViewById(R.id.txtcatname);
  27.  
  28. imageFlag = (ImageView) row.findViewById(R.id.catimage);
  29.  
  30. textViewCountry.setText(alNames.get(position));
  31. if (String.valueOf(alImages.get(position)) != "") {
  32.  
  33.  
  34. byte[] decode = Base64.decode(alImages.get(position), Base64.DEFAULT);
  35. Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
  36. bitmapResize(bitmap);
  37.  
  38. }
  39.  
  40.  
  41.  
  42. return row;
  43. }
  44. public void bitmapResize(Bitmap imageBitmap) {
  45.  
  46.  
  47. float widthbmp = imageBitmap.getWidth();
  48. float lengthbmp = imageBitmap.getHeight();
  49. // Get Screen width
  50. DisplayMetrics displaymetrics = new DisplayMetrics();
  51. context.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
  52. float hight = displaymetrics.heightPixels / 3;
  53. float width = displaymetrics.widthPixels / 3;
  54.  
  55. int convertHighet = (int) hight, convertWidth = (int) width;
  56.  
  57. // high length
  58. if (lengthbmp > hight) {
  59. convertHighet = (int) hight - 20;
  60. imageBitmap = Bitmap.createScaledBitmap(imageBitmap, convertWidth,
  61. convertHighet, true);
  62. }
  63.  
  64. // high width
  65. if (widthbmp > width) {
  66. convertWidth = (int) width - 20;
  67. imageBitmap = Bitmap.createScaledBitmap(imageBitmap, convertWidth,
  68. convertHighet, true);
  69. imageFlag.setImageBitmap(imageBitmap);
  70. }
  71.  
  72.  
  73. }
Add Comment
Please, Sign In to add comment