2016-11-11 2 views
-1

Ich entwickle eine App, die alle Albumcover-Bilder der Songs anzeigen. Also verwende ich Glide zum Laden und Zwischenspeichern von Bildern und um OutofMemoryError zu vermeiden.Gleiten funktioniert nicht? Dies ist der Fehler:

Das ist mein getView Methode im 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; 
} 

Und das ist der Fehler, den ich bekommen:

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

posten Sie Ihre glide Konfiguration – Raju

Antwort

1

Sie Zusammenhang mit Glide

Glide.with(this) // will not work 

Pass übergeben müssen Kontext von Ihrem Activity/Fragment zu AlbumAdapter

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

und verwenden, die Zusammenhang mit Glide

Glide.with(mContext) 

wenn Sie Activity haben, dann müssen Sie new AlbumAdapter(ActivityName.this) verwenden und für Fragment benötigen Sie new AlbumAdapter(getActivity())

+0

verwenden Es funktioniert dank. Aber ich bekomme diesen anderen Fehler: 11-11 11: 05: 55.866 11120-11120/com.xrobot.andrew.musicalbumsE/AndroidRuntime: FATALE AUSNAHME: Haupt Prozess: com.xrobot.andrew.musicalbums, PID: 11120 java .lang.OutOfMemoryError: OutOfMemoryError beim Versuch, OutOfMemoryError zu werfen; kein Stack-Trace verfügbar – xRobot

Verwandte Themen