0

ピカソで画像をロードしようとしています。 PicassoがURLから取得している画像を読み込もうとする部分を除いて、すべてが機能しています。アンドロイドスタジオピカソjava.lang.IllegalArgumentException:ターゲットはnullであってはなりません

java.lang.IllegalArgumentException:ターゲットをnullにすることはできません。 Picasso.with(mContext)

でしかし私は、本当の問題は

.into(holder.coverArtwork)だと思います;.

私はそれほど試しましたが、何が間違っているのか分かりません。それはすべての良い見えますが、私はそれを実行しようとするとクラッシュします。 log.dは、urlが正しいこと、そしてコンテキストに値があることを示しています。それは私が調べた分野の両方です。

以下は私のコードです。

import android.content.Context; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 

import com.squareup.picasso.Picasso; 

import org.json.JSONArray; 
import org.json.JSONObject; 

public class ParseJSON extends BaseAdapter { 



    Context mContext; 
    LayoutInflater mInflater; 
    JSONArray mJsonArray; 

    public ParseJSON(Context context, LayoutInflater inflater) { 

     mContext = context; 
     mInflater = inflater; 
     mJsonArray = new JSONArray(); 
     Log.v("Context Value:", "" + mContext); 
    } 



    public void updateData(JSONArray jsonArray) { 

     // update the adapter's dataset 
     mJsonArray = jsonArray; 
     notifyDataSetChanged(); 
    } 

    @Override public int getCount() {return mJsonArray.length(); 
    } 

    @Override public JSONObject getItem(int position) { 
     // your particular dataset uses String IDs 
     // but you have to put something in this method 
     return mJsonArray.optJSONObject(position); 
    } 

    @Override public long getItemId(int position) { 

     // your particular dataset uses String IDs 
     // but you have to put something in this method 
     return position; 
    } 

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

     ViewHolder holder; 

     // check if the view already exists 
     // if so, no need to inflate and findViewById again! 
     if (convertView == null) { 

      // Inflate the custom row layout from your XML. 
      convertView = mInflater.inflate(R.layout.music_list_layout, null); 

      // create a new "Holder" with subviews 
      holder = new ViewHolder(); 
      holder.musicSong = (TextView) convertView.findViewById(R.id.musicSong); 
      holder.musicArtist = (TextView) convertView.findViewById(R.id.musicArtist); 
      holder.musicGerne = (TextView) convertView.findViewById(R.id.musicGenre); 
      holder.musicTime = (TextView) convertView.findViewById(R.id.musicTime); 
      holder.coverArtwork = (ImageView) convertView.findViewById(R.id.songcover); 

      // hang onto this holder for future recyclage 
      convertView.setTag(holder); 
     } else { 

      // skip all the expensive inflation/findViewById 
      // and just get the holder you already made 
      holder = (ViewHolder) convertView.getTag(); 
     } 

     // Get the current book's data in JSON form 
     JSONObject jsonObject = getItem(position); 

     // See if there is a cover ID in the Object 
     if (jsonObject.has("artwork")) { 

      // If so, grab the Cover ID out from the object 
      String artworkUrl = jsonObject.optString("artwork"); 

      Log.d("Image Url", artworkUrl); 
      // Construct the image URL (specific to API) 
      String imageURL = artworkUrl; 


      // Use Picasso to load the image 
      // Temporarily have a placeholder in case it's slow to load 
      Picasso.with(mContext) 
        .load(imageURL) 
        .placeholder(R.drawable.sportmuziek) 
        .into(holder.coverArtwork); 

     } else { 

      // If there is no cover ID in the object, use a placeholder 
      holder.coverArtwork.setImageResource(R.drawable.sportmuziek); 
     } 

     // Grab the title and author from the JSON 
     String songname = ""; 
     String artistname = ""; 
     String musicgerne = ""; 
     String musictime = ""; 

     if (jsonObject.has("track_name")) { 
      songname = jsonObject.optString("track_name"); 
     } 

     if (jsonObject.has("artist")) { 
      artistname = jsonObject.optString("artist"); 
     } 

     if (jsonObject.has("tags")) { 
      musicgerne = jsonObject.optString("tags"); 
     } 

     if (jsonObject.has("time")) { 
      musictime = jsonObject.optString("time"); 
     } 

     // Send these Strings to the TextViews for display 
     holder.musicSong.setText(songname); 
     holder.musicArtist.setText(artistname); 
     holder.musicGerne.setText(musicgerne); 
     holder.musicTime.setText(musictime); 

     return convertView; 
    } 

    // this is used so you only ever have to do 
    // inflation and finding by ID once ever per View 
    private static class ViewHolder { 
     public TextView musicSong; 
     public TextView musicArtist; 
     public TextView musicGerne; 
     public TextView musicTime; 
     public ImageView coverArtwork; 
    } 
} 

私はAndroidスタジオにはかなり新しいので、ここでいくつかの助けが必要です。ありがとう

答えて

0

私はリストビューの画像を読み込んでいないが、別の画像を別のアクティビティに読み込んでいた。その部分はまったく考えられませんでした。

関連する問題