title: Android Application crashes while loading the thread
body: <p>I am trying to load the thumbnails of images and videos in the List view. While I am making their thumbnails, I provide a default thumbnail so that the task is easily done and therefore the thumbnail make and and load is put in a different thread. But the problem is the application crashes/exits. </p>
  
  <pre><code>public View getView(final int position, View convertView, ViewGroup parent) 
  {
  
      File file=new File(String.valueOf(filenames[position]));
      if(file.isDirectory()){
          img=R.drawable.folder;
      }
  
      else{
          img=getImage(filenames[position]);
      }
  
  
  
  
      ViewHolder viewHolder = null;
      if (convertView == null) {
          LayoutInflater inflator = LayoutInflater.from(getContext());
          convertView = inflator.inflate(R.layout.list_item, null);
          viewHolder = new ViewHolder();
          viewHolder.tv = (TextView) convertView.findViewById(R.id.textView1);
          viewHolder.cb = (CheckBox) convertView.findViewById(R.id.checkBox1);
          viewHolder.iv= (ImageView)convertView.findViewById(R.id.imageView);
          viewHolder.cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  int getPosition = (Integer) buttonView.getTag();  // Here we get the position that we have set for the checkbox using setTag.
                  myList.get(getPosition).setSelected(buttonView.isChecked()); // Set the value of checkbox to maintain its state.
              }
          });
          convertView.setTag(viewHolder);
          convertView.setTag(R.id.textView1, viewHolder.tv);
          convertView.setTag(R.id.checkBox1, viewHolder.cb);
          convertView.setTag(R.id.checkBox1, viewHolder.iv);
      }
      else {
          viewHolder = (ViewHolder) convertView.getTag();
      }
      viewHolder.iv.getLayoutParams().height = 80;
      viewHolder.iv.getLayoutParams().width = 80;
      viewHolder.cb.setTag(position); // This line is important.
  
      final ViewHolder finalViewHolder = viewHolder;
  
  
      Thread t2 = new Thread(){
  
          public void run(){
              if((String.valueOf(filenames[position])).contains(".jpeg")||String.valueOf(filenames[position]).contains(".jpg")||String.valueOf(filenames[position]).contains(".png")||String.valueOf(filenames[position]).contains(".bmp")||String.valueOf(filenames[position]).contains(".webp")||String.valueOf(filenames[position]).contains(".gif")){
                  thumb = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(String.valueOf(filenames[position])), 64, 64);
                  finalViewHolder.iv.setImageBitmap(thumb);
              }
              else if((String.valueOf(filenames[position])).contains(".mp4")||String.valueOf(filenames[position]).contains(".mkv")||String.valueOf(filenames[position]).contains(".webm")||String.valueOf(filenames[position]).contains(".3gp")||String.valueOf(filenames[position]).contains(".3gpp")){
                  thumb=ThumbnailUtils.createVideoThumbnail(filenames[position].getPath(), MediaStore.Video.Thumbnails.MINI_KIND);
                  finalViewHolder.iv.setImageBitmap(thumb);
              }
          }
      };
            finalViewHolder.iv.setImageResource(img);
            finalViewHolder.tv.setText(myList.get(position).getName());
            finalViewHolder.cb.setChecked(myList.get(position).isSelected());
   t2.start();
  
  
  
      return convertView;
  }
  </code></pre>
  
  <p>another option I have tried is:</p>
  
  <p>Making two threads, one that provide default thumbs and other same as t2 above. 
  None works. </p>