无法使用Picasso的URL从Firebase数据库加载图像

时间:2023-01-24 16:39:46

I am trying to Inflate a ListView with images stored on http://cloudinary.com/. The URL of the image is saved as a field in my Firebase Database. I am Using Picasso Client for the same. But What I notice in my database is that URL Link stored for each record is working fine. But When I try to retrieve the same in my code it shows URL is null As a toast. All other records are fetched properly and are working fine except the image.

我试图用存储在http://cloudinary.com/上的图像给ListView充气。图像的网址将保存为Firebase数据库中的字段。我正在使用Picasso Client。但我在我的数据库中注意到,为每条记录存储的URL链接工作正常。但是,当我尝试在我的代码中检索相同内容时,它显示URL为null作为Toa​​st。所有其他记录都正确获取并且除了图像之外工作正常。

1) Initializing my list view and setting the adapter.

1)初始化列表视图并设置适配器。

HomeSearchActivity.java

@Override
    protected void onStart() {

        databaseMember.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                memberList.clear();
                for (DataSnapshot memberSnapshot : dataSnapshot.getChildren()) {
                    Member_Pojo member = memberSnapshot.getValue(Member_Pojo.class);
                    Log.e(TAG, "onDataChange: " + member.getName());
                    memberList.add(member);
                }

                MembersListAdapter adapter = new MembersListAdapter(HomeSearchActivity.this, memberList);
                listViewHome.setAdapter(adapter);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
        super.onStart();
    }

2)Adapter Class for the listView

2)listView的适配器类

MembersListAdapter.java


import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Sumeet on 05-07-2017.
 */

public class MembersListAdapter extends ArrayAdapter<Member_Pojo> {

    private Activity context;
    // private Context c;
    private List<Member_Pojo> memberList;
    // CustomFilter filter;
    //  ArrayList<Member_Pojo> filterlist;


    public MembersListAdapter(Activity context, List<Member_Pojo> memberList) {
        super(context, R.layout.home_listview_display, memberList);
        this.context = context;
        this.memberList = memberList;
        //this.filterlist = (ArrayList<Member_Pojo>) memberList;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater();
        View listViewItem = inflater.inflate(R.layout.home_listview_display, null, true);

        TextView name_tv = (TextView) listViewItem.findViewById(R.id.tv_name_display);
        TextView town_tv = (TextView) listViewItem.findViewById(R.id.tv_town_display);
        TextView id = (TextView) listViewItem.findViewById(R.id.textViewID);
        ImageView imageView_dp = (ImageView) listViewItem.findViewById(R.id.imageView_dps);
        Member_Pojo member = memberList.get(position);

        name_tv.setText(member.getName());
        town_tv.setText(member.getTownP());
        id.setText(member.getId());

        Toast.makeText(context, "URL IS :  " + member.getDP_URL(), Toast.LENGTH_SHORT).show();
       Toast.makeText(context, "name IS :  " + member.getName(), Toast.LENGTH_SHORT).show();
        PicassoClient.downloadImage(context, member.getDP_URL(), imageView_dp);
       imageView_dp.setImageResource(member.getDP_URL());

        return listViewItem;

    }

}

3) Downloading the image Using Picasso: here Only the Placeholder image I displayed. The reason to which I suppose is that the class is passed a null value.(Tried Using the log before passing the value, and it showed NULL.)

3)下载图像使用Picasso:此处仅显示我显示的占位符图像。我想的原因是该类传递了一个空值。(尝试在传递值之前使用日志,它显示为NULL。)

import android.content.Context;
import android.util.Log;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

/**
 * Created by Sumeet on 15-07-2017.
 */

public class PicassoClient {
    public static void downloadImage(Context c, String url, ImageView img) {
        if (url != null && url.length() > 0) {
            Picasso.with(c).load(url).placeholder(R.drawable.noimage).into(img);
            Log.e("myTag", "URL is not null" + url);
        } else {
            Picasso.with(c).load(R.drawable.noimage).into(img);
            Log.e("myTag", "URL is  null");
        }
    }
}

4)below is the log output

4)下面是日志输出

                                                 [ 07-16 15:48:30.305 22740:22740 D/         ]
                                                 HostConnection::get() New Host Connection established 0x77f95fc15420, tid 22740
07-16 15:48:30.321 22740-22804/com.example.sumeet.kalwardirectorytry1 D/NetworkSecurityConfig: No Network Security Config specified, using platform default

                                                                                               [ 07-16 15:48:30.379 22740:22803 D/         ]
                                                                                               HostConnection::get() New Host Connection established 0x77f95fc15cc0, tid 22803
07-16 15:48:30.380 1298-3194/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-16 15:48:30.381 22740-22803/com.example.sumeet.kalwardirectorytry1 I/OpenGLRenderer: Initialized EGL, version 1.4
07-16 15:48:30.382 22740-22803/com.example.sumeet.kalwardirectorytry1 D/OpenGLRenderer: Swap behavior 1
07-16 15:48:30.382 22740-22803/com.example.sumeet.kalwardirectorytry1 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
07-16 15:48:30.382 22740-22803/com.example.sumeet.kalwardirectorytry1 D/OpenGLRenderer: Swap behavior 0
07-16 15:48:30.394 1298-3194/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-16 15:48:30.423 1298-3194/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-16 15:48:30.511 22740-22740/com.example.sumeet.kalwardirectorytry1 W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
07-16 15:48:30.724 2898-2898/com.android.inputmethod.latin W/InputMethodService: Window size has been changed. This may cause jankiness of resizing window: -1 -> -2
07-16 15:48:30.727 2098-2355/system_process I/ActivityManager: Displayed com.example.sumeet.kalwardirectorytry1/.HomeSearchActivity: +2s66ms
07-16 15:48:30.736 22740-22783/com.example.sumeet.kalwardirectorytry1 D/FA: Connected to remote service
07-16 15:48:30.736 22740-22783/com.example.sumeet.kalwardirectorytry1 V/FA: Processing queued up service tasks: 2
07-16 15:48:30.775 2898-2898/com.android.inputmethod.latin I/LatinIME: Starting input. Cursor position = -1,-1
07-16 15:48:30.776 2898-2898/com.android.inputmethod.latin E/RichInputConnection: Unable to connect to the editor to retrieve text.
07-16 15:48:30.776 2898-2898/com.android.inputmethod.latin D/RichInputConnection: Will try to retrieve text later.
07-16 15:48:30.777 2898-2898/com.android.inputmethod.latin I/InputAttributes: InputType.TYPE_NULL is specified
07-16 15:48:30.827 1298-1298/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
07-16 15:48:30.829 1298-1298/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
07-16 15:48:30.919 2098-2355/system_process D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
07-16 15:48:30.940 2898-2898/com.android.inputmethod.latin I/LatinIME: Starting input. Cursor position = 0,0
07-16 15:48:31.085 1298-1617/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-16 15:48:31.103 1298-1616/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-16 15:48:31.123 1298-1616/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-16 15:48:31.522 4179-4179/com.google.android.gms.unstable W/Binder:4179_2: type=1400 audit(0.0:15): avc: denied { read } for name="/" dev="tmpfs" ino=4097 scontext=u:r:priv_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=dir permissive=0
07-16 15:48:32.909 3847-4858/com.google.android.gms.persistent W/Conscrypt: Could not set socket write timeout: null
07-16 15:48:33.178 3847-4858/com.google.android.gms.persistent W/Conscrypt: Could not set socket write timeout: null
07-16 15:48:33.246 1311-1366/? D/AudioFlinger: mixer(0xebc83900) throttle end: throttle time(18)
07-16 15:48:33.373 2898-2898/com.android.inputmethod.latin W/InputMethodService: Window size has been changed. This may cause jankiness of resizing window: -1 -> -2
07-16 15:48:33.609 3847-4858/com.google.android.gms.persistent W/GLSUser: [AppCertManager] IOException while requesting key: 
                                                                          java.io.IOException: Invalid device key response.
                                                                              at evk.a(:com.google.android.gms:274)
                                                                              at evk.a(:com.google.android.gms:4238)
                                                                              at evj.a(:com.google.android.gms:45)
                                                                              at evd.a(:com.google.android.gms:50)
                                                                              at evc.a(:com.google.android.gms:104)
                                                                              at com.google.android.gms.auth.account.be.legacy.AuthCronChimeraService.b(:com.google.android.gms:4049)
                                                                              at ecm.call(:com.google.android.gms:2041)
                                                                              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                              at llt.run(:com.google.android.gms:450)
                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                              at lqc.run(:com.google.android.gms:17)
                                                                              at java.lang.Thread.run(Thread.java:761)
07-16 15:48:35.848 22740-22740/com.example.sumeet.kalwardirectorytry1 W/ClassMapper: No setter/field for dp_URL found on class com.example.sumeet.kalwardirectorytry1.Member_Pojo (fields/setters are case sensitive!)
07-16 15:48:35.851 22740-22740/com.example.sumeet.kalwardirectorytry1 E/myTag: onDataChange: Sumeet
07-16 15:48:35.852 22740-22740/com.example.sumeet.kalwardirectorytry1 W/ClassMapper: No setter/field for dp_URL found on class com.example.sumeet.kalwardirectorytry1.Member_Pojo (fields/setters are case sensitive!)
07-16 15:48:35.852 22740-22740/com.example.sumeet.kalwardirectorytry1 E/myTag: onDataChange: Sumeet Shah
07-16 15:48:35.855 22740-22783/com.example.sumeet.kalwardirectorytry1 V/FA: Inactivity, disconnecting from the service
07-16 15:48:35.894 22740-22740/com.example.sumeet.kalwardirectorytry1 W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
07-16 15:48:35.912 22740-22740/com.example.sumeet.kalwardirectorytry1 E/myTag: URL is  null
07-16 15:48:35.915 22740-22740/com.example.sumeet.kalwardirectorytry1 E/myTag: URL is  null
07-16 15:48:38.917 3567-22923/? I/ContextCompilationHandl: Compiling grammar for: en-US, type=CONTACT_DIALING
07-16 15:48:38.922 3567-22923/? I/ContextCompilationHandl: No grammar compilation resources for COMPILER, aborting. 
07-16 15:48:38.922 3567-22923/? I/ContextCompilationHandl: Compiling grammar for: en-US, type=HANDS_FREE_COMMANDS
07-16 15:48:38.923 3567-22923/? I/ContextCompilationHandl: No grammar compilation resources for COMPILER, aborting. 
07-16 15:48:38.923 3567-22923/? I/ContextCompilationHandl: Compiling grammar for: en-US, type=CONTACT_NAMES
07-16 15:48:38.927 3567-22923/? I/ContextCompilationHandl: No grammar compilation resources for VOICE_ACTIONS_COMPILER, aborting. 
07-16 15:48:38.928 3567-22923/? I/ContextCompilationHandl: Compiling grammar for: en-US, type=APP_NAMES
07-16 15:48:38.930 3567-22923/? I/ContextCompilationHandl: No grammar compilation resources for VOICE_ACTIONS_COMPILER, aborting. 
07-16 15:48:38.930 3567-22923/? I/ContextCompilationHandl: Compiling grammar for: en-US, type=MUSIC_NAMES
07-16 15:48:38.934 3567-22923/? I/ContextCompilationHandl: No grammar compilation resources for VOICE_ACTIONS_COMPILER, aborting. 
07-16 15:48:40.274 22740-22783/com.example.sumeet.kalwardirectorytry1 V/FA: Session started, time: 1485812
07-16 15:48:40.281 22740-22783/com.example.sumeet.kalwardirectorytry1 I/FA: Tag Manager is not found and thus will not be used
07-16 15:48:40.288 22740-22783/com.example.sumeet.kalwardirectorytry1 D/FA: Logging event (FE): _s, Bundle[{_o=auto, _sc=HomeSearchActivity, _si=-7738148218987138517}]
07-16 15:48:40.306 22740-22783/com.example.sumeet.kalwardirectorytry1 V/FA: Using measurement service
07-16 15:48:40.306 22740-22783/com.example.sumeet.kalwardirectorytry1 V/FA: Connecting to remote service
07-16 15:48:40.317 22740-22783/com.example.sumeet.kalwardirectorytry1 D/FA: Connected to remote service
07-16 15:48:40.317 22740-22783/com.example.sumeet.kalwardirectorytry1 V/FA: Processing queued up service tasks: 1
07-16 15:48:40.335 3533-22811/com.google.android.gms V/FA-SVC: Logging event: origin=auto,name=_s,params=Bundle[mParcelledData.dataSize=120]
07-16 15:48:40.340 3533-22811/com.google.android.gms V/FA-SVC: Saving event, name, data size: _s, 64
07-16 15:48:40.341 3533-22811/com.google.android.gms V/FA-SVC: Event recorded: Event{appId='com.example.sumeet.kalwardirectorytry1', name='_s', params=Bundle[{_o=auto, _sc=HomeSearchActivity, _si=-7738148218987138517}]}
07-16 15:48:40.345 3533-22811/com.google.android.gms V/FA-SVC: Upload scheduled in approximately ms: 2374370
07-16 15:48:40.347 3533-22811/com.google.android.gms V/FA-SVC: Background event processing time, ms: 12
07-16 15:48:45.335 22740-22783/com.example.sumeet.kalwardirectorytry1 V/FA: Inactivity, disconnecting from the service
07-16 15:49:27.772 3567-3567/? I/GrammarCompilationSvcCt: #startService for null, APP_NAMES.
07-16 15:49:27.777 3567-23636/? I/ContextCompilationHandl: Compiling grammar for: en-US, type=APP_NAMES

Can you Please let me know where am I going wrong on this? Any Help On this is really appreciated.

1 个解决方案

#1


0  

I had very similar issue with downloading and showing images in adapter using Picasso. Try Glide

我使用Picasso在适配器中下载和显示图像时遇到了类似的问题。试试Glide

This solved problem in my case.

这解决了我的问题。

#1


0  

I had very similar issue with downloading and showing images in adapter using Picasso. Try Glide

我使用Picasso在适配器中下载和显示图像时遇到了类似的问题。试试Glide

This solved problem in my case.

这解决了我的问题。