1

에 :내가 예외 메시지를해서 ProgressDialog 내가 recyclerview 어댑터를해서 ProgressDialog를 사용하려고하면 RecyclerView 어댑터 문제

Unable to add window -- token null is not for an application 

내가 ProgressBar의 아래 글라이드 몇 줄의이 같은 컨텍스트를 사용하기 때문에 사용 환경에 모든 괜찮다는 것을 알고있다. 어떤 생각이라도 문제가 뭐니? 내 어댑터 클래스 :

import android.app.ProgressDialog; 
import android.content.Context; 
import android.support.v7.widget.RecyclerView; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ImageView; 

import com.bumptech.glide.Glide; 
import com.bumptech.glide.load.resource.drawable.GlideDrawable; 
import com.bumptech.glide.request.RequestListener; 
import com.bumptech.glide.request.target.Target; 

import java.util.List; 



public class ShopsAdapter extends RecyclerView.Adapter<ShopsAdapter.MyViewHolder> { 

    Context mContext; 
    List<String> shopsList; 
    ProgressDialog progressDialog; 

    public class MyViewHolder extends RecyclerView.ViewHolder { 
     public ImageView thumbnail; 

     public MyViewHolder(View view) { 
      super(view); 
      thumbnail = (ImageView) view.findViewById(R.id.thumbnail); 

     } 
    } 

    public ShopsAdapter(Context mContext, List<String> shopsList) { 
     this.mContext = mContext; 
     this.shopsList = shopsList; 
    } 


    @Override 
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View itemView = LayoutInflater.from(parent.getContext()) 
       .inflate(R.layout.shop_card,parent,false); 

     return new MyViewHolder(itemView); 
    } 

    @Override 
    public void onBindViewHolder(MyViewHolder holder, int position) { 
     progressDialog = new ProgressDialog(mContext); 

     shopsList.get(position); 
     try{ 
      progressDialog.show(); 
      String stringformat = String.format(".../%s.png", shopsList.get(position)); 
      Glide.with(mContext).load(stringformat).listener(new RequestListener<String, GlideDrawable>() { 
       @Override 
       public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { 
        return false; 
       } 

       @Override 
       public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { 
        //progressDialog.setVisibility(View.GONE); 
        return false; 
       } 
      }).centerCrop().fitCenter().into(holder.thumbnail); 
     }catch (Exception e){ 
      Log.d("Dsdfs", e.getMessage()); 
      Glide.with(mContext).load("http://...Zabka.png").centerCrop().fitCenter().into(holder.thumbnail); 
     } 



    } 

    @Override 
    public int getItemCount() { 
     return shopsList.size(); 
    } 
} 
+0

ur 어댑터 호출 코드 – jagapathi

+0

어댑터 = 새 ShopsAdapter (getApplicationContext(), shopsNames); –

답변

1

변경

어댑터 = 새로운 ShopsAdapter (getApplicationContext(), shopsNames);

TO 어댑터 = 새로운 ShopsAdapter (이, shopsNames);

+0

어댑터가 AsyncTask 클래스 내에서 호출되기 때문에 연결할 수 없습니다. –

+0

작동하지 않는 경우 CLASS_NAME.this class_name은 액티비티 이름입니다. – jagapathi

+0

adapter = new ShopsAdapter (classname.this, shopsNames); – jagapathi