Guest User

Untitled

a guest
Aug 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. NullPoointerException pulling images from cash using hascode?
  2. public String [] myRemoteImages = {imageUrl,imageUrl2,imageUrl3,imageUrl4,imageUrl5,imageUrl6,imageUrl7};
  3.  
  4. protected void onPostExecute(Void notUsed){
  5. Log.e("URLS", imageUrl + imageUrl2 + imageUrl3 + imageUrl4 + imageUrl5 + imageUrl6 + imageUrl7);
  6.  
  7.  
  8.  
  9. adapter=new LazyAdapter(MainMenu.this, myRemoteImages);
  10. ((Gallery) findViewById(R.id.gallery))
  11. .setAdapter(adapter);
  12.  
  13. adapter.notifyDataSetChanged();
  14.  
  15. public LazyAdapter(Activity a, String[] d) {
  16. activity = a;
  17. data=d;
  18. inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  19. imageLoader=new ImageLoader(activity.getApplicationContext());
  20. }
  21.  
  22. public int getCount() {
  23. return data.length;
  24. }
  25.  
  26. public Object getItem(int position) {
  27. return position;
  28. }
  29.  
  30. public long getItemId(int position) {
  31. return position;
  32. }
  33.  
  34. public View getView(int position, View convertView, ViewGroup parent) {
  35. View vi=convertView;
  36. if(convertView==null)
  37. vi = inflater.inflate(R.layout.lazyitemt, null);
  38.  
  39.  
  40. ImageView image=(ImageView)vi.findViewById(R.id.imageView);
  41.  
  42. image.setLayoutParams(new LinearLayout.LayoutParams(250, 250));
  43. imageLoader.DisplayImage(data[position], activity, image);
  44. return vi;
  45. }
  46.  
  47. //Error here Nullpointer.
  48. String filename=String.valueOf(url.hashCode());
  49. File f = new File(cacheDir, filename);
  50. return f;
  51.  
  52. }
  53.  
  54. private Bitmap getBitmap(String url)
  55. {
  56. File f=fileCache.getFile(url);
  57.  
  58. //from SD cache
  59. Bitmap b = decodeFile(f);
  60. if(b!=null)
  61. return b;
  62.  
  63. //from web
  64. try {
  65. Bitmap bitmap=null;
  66. URL imageUrl = new URL(url);
  67. HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
  68. conn.setConnectTimeout(30000);
  69. conn.setReadTimeout(30000);
  70. InputStream is=conn.getInputStream();
  71. OutputStream os = new FileOutputStream(f);
  72. Utils.CopyStream(is, os);
  73. os.close();
  74. bitmap = decodeFile(f);
  75. return bitmap;
  76. } catch (Exception ex){
  77. ex.printStackTrace();
  78. return null;
  79. }
  80. }
Add Comment
Please, Sign In to add comment