Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NullPoointerException pulling images from cash using hascode?
- public String [] myRemoteImages = {imageUrl,imageUrl2,imageUrl3,imageUrl4,imageUrl5,imageUrl6,imageUrl7};
- protected void onPostExecute(Void notUsed){
- Log.e("URLS", imageUrl + imageUrl2 + imageUrl3 + imageUrl4 + imageUrl5 + imageUrl6 + imageUrl7);
- adapter=new LazyAdapter(MainMenu.this, myRemoteImages);
- ((Gallery) findViewById(R.id.gallery))
- .setAdapter(adapter);
- adapter.notifyDataSetChanged();
- public LazyAdapter(Activity a, String[] d) {
- activity = a;
- data=d;
- inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- imageLoader=new ImageLoader(activity.getApplicationContext());
- }
- public int getCount() {
- return data.length;
- }
- public Object getItem(int position) {
- return position;
- }
- public long getItemId(int position) {
- return position;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- View vi=convertView;
- if(convertView==null)
- vi = inflater.inflate(R.layout.lazyitemt, null);
- ImageView image=(ImageView)vi.findViewById(R.id.imageView);
- image.setLayoutParams(new LinearLayout.LayoutParams(250, 250));
- imageLoader.DisplayImage(data[position], activity, image);
- return vi;
- }
- //Error here Nullpointer.
- String filename=String.valueOf(url.hashCode());
- File f = new File(cacheDir, filename);
- return f;
- }
- private Bitmap getBitmap(String url)
- {
- File f=fileCache.getFile(url);
- //from SD cache
- Bitmap b = decodeFile(f);
- if(b!=null)
- return b;
- //from web
- try {
- Bitmap bitmap=null;
- URL imageUrl = new URL(url);
- HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
- conn.setConnectTimeout(30000);
- conn.setReadTimeout(30000);
- InputStream is=conn.getInputStream();
- OutputStream os = new FileOutputStream(f);
- Utils.CopyStream(is, os);
- os.close();
- bitmap = decodeFile(f);
- return bitmap;
- } catch (Exception ex){
- ex.printStackTrace();
- return null;
- }
- }
Add Comment
Please, Sign In to add comment