簡體   English   中英

畢加索出現錯誤:java.lang.IllegalArgumentException:路徑不能為空

[英]Picasso getting error : java.lang.IllegalArgumentException: Path must not be empty

我正在使用公共 API 並使用畢加索從系統加載數據來制作在線新聞。 我的應用程序運行順利。 但是,應用程序有時會崩潰並顯示錯誤

 at com.squareup.picasso.Picasso.load(Picasso.java:332)
    at com.tonyapp.hoanguhsk.CustomAdapter.onBindViewHolder(CustomAdapter.java:49)
    at com.tonyapp.hoanguhsk.CustomAdapter.onBindViewHolder(CustomAdapter.java:20)
    at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7254)
    at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7337)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6194)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6460)
    at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
    at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
    at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
    at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
    at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我檢查了我的 customAdapter.java 文件並嘗試修復 Java:49 處的錯誤。 我嘗試測試和使用許多解決方案,這些解決方案是從其他與我的案例有相同問題的人那里搜索的。 不幸的是,錯誤仍然顯示。 下面幾行是我的 CustomAdapter.java 代碼:

 holder.text_title.setText(headlines.get(position).getTitle());
    holder.text_source.setText(headlines.get(position).getAuthor());
    holder.txt_date.setText(headlines.get(position).getPublishedAt());




    if (headlines.get(position).getUrlToImage()!=null){
        Picasso.get().load(headlines.get(position).getUrlToImage()).into(holder.img_headline);
    }

    holder.cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            listener.OnNewsClicked(headlines.get(position));
            Intent intent = new Intent(context,Webview.class);
            intent.putExtra("url",headlines.get(position).getUrl());
            context.startActivity(intent);

誰能幫我解決這個崩潰? 非常感謝您的支持。

根據您的代碼嘗試更改代碼如下

 if (headlines.get(position).getUrlToImage()!=null && !headlines.get(position).getUrlToImage().isEmpty()){
    Picasso.get().load(headlines.get(position).getUrlToImage()).into(holder.img_headline);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM