2016-11-11 3 views
-1

Я разрабатываю приложение, которое отображает все обложки обложек альбомов. Так что я использую скольжение для загрузки и кэширования изображений и для исключения OutofMemoryError.Glide не работает? Это ошибка:

Это мой метод GetView в AlbumAdapter:

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    RelativeLayout albumsLay = (RelativeLayout)songInf.inflate 
      (R.layout.album_layout, parent, false); 
    ImageView coverView = (ImageView)albumsLay.findViewById(R.id.song_cover); 

    //get song using position 
    Song currSong = songs.get(position); 

    if (Drawable.createFromPath(currSong.getCover()) != null) { 
     Drawable img = Drawable.createFromPath(currSong.getCover()); 
        Glide.with(this).load(img).into(coverView); 

    } 

    albumsLay.setTag(position); 
    return albumsLay; 
} 

И это ошибка, я получаю:

Error:(77, 18) error: no suitable method found for with(AlbumAdapter) 
method Glide.with(android.support.v4.app.Fragment) is not applicable 
(actual argument AlbumAdapter cannot be converted to android.support.v4.app.Fragment by method invocation conversion) 
method Glide.with(android.app.Fragment) is not applicable 
(actual argument AlbumAdapter cannot be converted to android.app.Fragment by method invocation conversion) 
method Glide.with(FragmentActivity) is not applicable 
(actual argument AlbumAdapter cannot be converted to FragmentActivity by method invocation conversion) 
method Glide.with(Activity) is not applicable 
(actual argument AlbumAdapter cannot be converted to Activity by method invocation conversion) 
method Glide.with(Context) is not applicable 
(actual argument AlbumAdapter cannot be converted to Context by method invocation conversion) 
+0

опубликовать конфигурацию глиссады – Raju

ответ

1

вам нужно передать контекст с Glide

Glide.with(this) // will not work 

Pass контекста от вашего Activity/Fragment до AlbumAdapter

Context mContext; 
public AlbumAdapter(Context context){ 
    mContext = context; 
} 

И использовать этот контекст с Glide

Glide.with(mContext) 

если у вас есть Activity, то вам нужно использовать new AlbumAdapter(ActivityName.this) и Fragment вам нужно использовать new AlbumAdapter(getActivity())

+0

Он работает спасибо. Но я получаю эту другую ошибку: 11-11 11: 05: 55.866 11120-11120/com.xrobot.andrew.musicalbumsE/AndroidRuntime: FATAL EXCEPTION: main Процесс: com.xrobot.andrew.musicalbums, PID: 11120 java .lang.OutOfMemoryError: OutOfMemoryError, брошенный при попытке выбросить OutOfMemoryError; нет трассировки стека – xRobot