FireBase 实时数据库:回收站视图未填充

Posted

技术标签:

【中文标题】FireBase 实时数据库:回收站视图未填充【英文标题】:FireBase Realtime Database : Recycler View not populating 【发布时间】:2021-09-29 05:17:20 【问题描述】:

我的回收站视图打开,显示黑屏几秒钟,然后返回到我的登录活动。

这是我的适配器类...

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;

public class MainAdapter extends FirebaseRecyclerAdapter<items, MainAdapter.myViewHolder> 

    public MainAdapter(@NonNull FirebaseRecyclerOptions<items> options) 
        super(options);
    

    @Override
    protected void onBindViewHolder(@NonNull myViewHolder holder, int position, @NonNull items model) 
        holder.Product.setText(model.getProduct());
        holder.Price.setText(model.getPrice());
        holder.Stock.setText(model.getStock());
    

    @NonNull
    @Override
    public myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) 
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.display_item,parent,false);
        return new myViewHolder(view);
    

    class myViewHolder extends RecyclerView.ViewHolder
        TextView Product, Price, Stock;

        public myViewHolder(@NonNull View itemView) 
            super(itemView);
            Price=(TextView)itemView.findViewById(R.id.Price);
            Product=(TextView)itemView.findViewById(R.id.Product);
            Stock=(TextView)itemView.findViewById(R.id.Stock);
        
    

这是我的主要课程


import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.Toast;

import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;

public class Main extends AppCompatActivity 
    private RecyclerView recyclerView;
    private MainAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        recyclerView=findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(Main.this));
        FirebaseRecyclerOptions<items> options =
                new FirebaseRecyclerOptions.Builder<items>()
                        .setQuery(FirebaseDatabase.getInstance().getReference().child("Cups"),items.class)
                        .build();

        adapter= new MainAdapter(options);
        recyclerView.setAdapter(adapter);
    
    @Override
    protected void onStart() 
        super.onStart();
        Toast.makeText(this, "Working", Toast.LENGTH_SHORT).show();
        adapter.startListening();
    

    @Override
    protected void onStop() 
        super.onStop();
        Toast.makeText(this, " not Working", Toast.LENGTH_SHORT).show();

        adapter.stopListening();
    

这里是 logcat(Error) No Filters

2021-07-22 15:41:10.222 17121-17121/? E/facebook.katan: Not starting debugger since process cannot load the jdwp agent.
2021-07-22 15:41:10.565 17121-17152/? E/appstatelogger2: Can't run on P or newer
2021-07-22 15:41:10.583 17121-17157/? E/dalvik-internals: attempting to hook OatFileManager::HasCollisions
2021-07-22 15:41:10.587 17121-17157/? E/dalvik-internals: could not hook _ZNK3art14OatFileManager13HasCollisionsEPKNS_7OatFileEPKNS_18ClassLoaderContextEPNSt3__112basic_stringIcNS7_11ch
2021-07-22 15:41:10.587 17121-17157/? E/dalvik-internals: attempting to hook OatFileAssistant::IsUpToDate
2021-07-22 15:41:10.589 17121-17157/? E/dalvik-internals: attempting to hook OatFileAssistant::IsUpToDate
2021-07-22 15:41:10.592 17121-17157/? E/dalvik-internals: could not hook _ZN3art16OatFileAssistant17OatFileIsUpToDateEv
2021-07-22 15:41:10.592 17121-17157/? E/dalvik-internals: attempting to hook OatFileAssistant::IsUpToDate
2021-07-22 15:41:10.597 17121-17157/? E/dalvik-internals: could not hook _ZN3art16OatFileAssistant18OdexFileIsUpToDateEv
2021-07-22 15:41:10.597 17121-17157/? E/dalvik-internals: attempting to hook OatFileAssistant::IsUpToDate
2021-07-22 15:41:10.600 17121-17157/? E/dalvik-internals: could not hook _ZN3art16OatFileAssistant22GivenOatFileIsUpToDateERKNS_7OatFileE
2021-07-22 15:41:10.966 17121-17157/? E/nightwatch-fd: Unable to open /proc/self/oom_adj (mode read) : 13 : Permission denied
2021-07-22 15:41:10.966 17121-17157/? E/nightwatch-fd: Unable to open /proc/self/oom_score_adj (mode read) : 13 : Permission denied
2021-07-22 15:41:11.014 1442-1442/? E/OPPO_KEVENT_RECORD: oppo_kevent Receive message from kernel, event_type=3
2021-07-22 15:41:11.014 1442-1442/? E/OPPO_KEVENT_RECORD: OPPO_KEVENT payload:10316,path@@/data/app/com.facebook.katana-A3yDUxyptfeE9lxYzQ7ziQ==/lib/arm64/libwatcher_binary.so
2021-07-22 15:41:11.016 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:11.016 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:11.046 17219-17219/? A/linker: CANNOT LINK EXECUTABLE "/data/data/com.facebook.katana/app_errorreporting/sess__000002035-1626948670386-cb5f3fa5-6e6a-0704-da63-0c86cb77ab08/nightwatch.txt": library "libclang_rt.xray.so" not found
2021-07-22 15:41:11.076 17121-17217/? E/nightwatch-target: lmkd signal waiters
2021-07-22 15:41:11.077 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:11.077 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:12.077 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:12.078 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:13.120 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:13.120 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:13.928 15771-15974/? E/nightwatch-target: lmkd signal waiters
2021-07-22 15:41:13.932 3156-3156/? E/PhoneInterfaceManager: [PhoneIntfMgr] getCarrierPackageNamesForIntent: No UICC
2021-07-22 15:41:13.934 17121-17217/? E/nightwatch-target: lmkd signal waiters
2021-07-22 15:41:13.937 3156-3156/? E/PhoneInterfaceManager: [PhoneIntfMgr] getCarrierPackageNamesForIntent: No UICC
2021-07-22 15:41:14.126 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:14.126 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:15.129 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:15.129 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:16.159 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:16.159 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:16.865 4914-4949/? E/OpenID: com.heytap.mcs:DUID:ret:T
2021-07-22 15:41:16.927 1789-4085/? E/TaskPersister: File error accessing recents directory (directory doesn't exist?).
2021-07-22 15:41:17.207 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:17.208 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:17.288 1789-1789/? E/TransmessgeManager: achieve hal service failed
2021-07-22 15:41:17.420 1247-7781/? E/installd: Failed to delete /data/app/vmdl318392684.tmp: No such file or directory
2021-07-22 15:41:17.450 1789-5223/? E/OppoPackageManager: parserFilterAppList() xml empty, return.
2021-07-22 15:41:17.559 1789-5221/? E/OppoPackageManager: parserFilterAppList() xml empty, return.
2021-07-22 15:41:17.732 3156-3156/? E/PhoneInterfaceManager: [PhoneIntfMgr] getCarrierPackageNamesForIntent: No UICC
2021-07-22 15:41:17.744 3156-3156/? E/PhoneInterfaceManager: [PhoneIntfMgr] getCarrierPackageNamesForIntent: No UICC
2021-07-22 15:41:17.766 1789-2123/? E/system_server: Invalid ID 0x00000000.
2021-07-22 15:41:17.866 3156-3156/? E/PhoneInterfaceManager: [PhoneIntfMgr] getCarrierPackageNamesForIntent: No UICC
2021-07-22 15:41:17.876 3156-3156/? E/PhoneInterfaceManager: [PhoneIntfMgr] getCarrierPackageNamesForIntent: No UICC
2021-07-22 15:41:17.879 15771-15974/? E/nightwatch-target: lmkd signal waiters
2021-07-22 15:41:18.004 15740-17371/? E/route: try findMethod[market://PackageReceiverRouter/Void_onReceive_Context_Intent], result = null!!
2021-07-22 15:41:18.008 17364-17364/? E/le.silkenscoop: Unknown bits set in runtime_flags: 0x8000
2021-07-22 15:41:18.062 1789-4781/? E/OppoPackageManager: parserFilterAppList() xml empty, return.
2021-07-22 15:41:18.065 13654-17362/? E/route: try findMethod[gamecenter://PackageReceiverRouter/Void_onReceive_Context_Intent], result = null!!
2021-07-22 15:41:18.114 4030-4064/? E/oiface: packageSwitch pkg com.example.silkenscoops, enter
2021-07-22 15:41:18.114 4030-4064/? E/oiface: current package is com.example.silkenscoops
2021-07-22 15:41:18.127 4030-4054/? E/oiface: Average freq 0 for 0s.
2021-07-22 15:41:18.127 4030-4054/? E/oiface: Average freq 0 for 0s.
2021-07-22 15:41:18.134 4030-4054/? E/oiface: client  not found, skipped
2021-07-22 15:41:18.154 1789-3304/? E/OppoPackageManager: parserFilterAppList() xml empty, return.
2021-07-22 15:41:18.183 15771-15974/? E/nightwatch-target: lmkd signal waiters
2021-07-22 15:41:18.208 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:18.209 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:18.513 774-17421/? E/ResolverController: No valid NAT64 prefix (100, <unspecified>/0)
2021-07-22 15:41:18.518 4914-4949/? E/OpenID: com.nearme.statistics.rom:DUID:ret:T
2021-07-22 15:41:18.525 4914-4949/? E/OpenID: com.nearme.statistics.rom:OUID:ret:T
2021-07-22 15:41:18.527 4914-4949/? E/OpenID: com.nearme.statistics.rom:GUID:ret:T
2021-07-22 15:41:18.535 4914-4949/? E/OpenID: com.nearme.statistics.rom:OUID_STATUS:ret:T
2021-07-22 15:41:18.561 774-17419/? E/ResolverController: No valid NAT64 prefix (100, <unspecified>/0)
2021-07-22 15:41:18.707 1789-3252/? E/WindowManager: App trying to use insecure INPUT_FEATURE_NO_INPUT_CHANNEL flag. Ignoring
2021-07-22 15:41:18.871 15771-15974/? E/nightwatch-target: lmkd signal waiters
2021-07-22 15:41:19.068 3641-14933/? E/NetworkScheduler.ATC: Called cancelTask for already completed task com.google.android.gms/.measurement.PackageMeasurementTaskServiceu=0 tag="Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG" trigger=windowstart=149s,end=299s,earliest=-547s,latest=-397s requirements=[NET_CONNECTED] attributes=[PERSISTED] scheduled=-696s last_run=-380s exec_window_multiplier=1.0000 jid=N/A status=ACTIVE retries=0 client_lib=GMS_TASK_SCHEDULER-212418000 :1 [CONTEXT service_id=218 ]
2021-07-22 15:41:19.182 6857-6857/? E/ANR_LOG: >>> msg's executing time is too long
2021-07-22 15:41:19.182 6857-6857/? E/ANR_LOG: Blocked msg =  when=-1s615ms what=0 target=android.os.Handler callback=wyd  , cost  = 1615 ms
2021-07-22 15:41:19.182 6857-6857/? E/ANR_LOG: >>>Current msg List is:
2021-07-22 15:41:19.183 6857-6857/? E/ANR_LOG: Current msg <1>  =  when=-1s190ms what=113 target=android.app.ActivityThread$H obj=ReceiverDataintent=Intent  act=android.intent.action.PACKAGE_ADDED dat=package:com.example.silkenscoops flg=0x4000010 pkg=com.android.vending cmp=com.android.vending/com.google.android.finsky.packagemanager.impl.PackageMonitorReceiverImpl$RegisteredReceiver (has extras)  packageName=com.android.vending resultCode=0 resultData=null resultExtras=null 
2021-07-22 15:41:19.183 6857-6857/? E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<
2021-07-22 15:41:19.227 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:19.227 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:19.258 774-17460/? E/ResolverController: No valid NAT64 prefix (100, <unspecified>/0)
2021-07-22 15:41:19.313 17121-17465/? E/fb4a.VpsReliableMediaMonitorImpl: TigonVideoService initHybrid
2021-07-22 15:41:19.367 870-870/? E/soundtrigger: audio_extn_sound_trigger_set_parameters: str_params NULL
2021-07-22 15:41:19.386 774-17469/? E/ResolverController: No valid NAT64 prefix (100, <unspecified>/0)
2021-07-22 15:41:19.396 1319-1319/? E/OMX-VDEC-1080P: Unsupported output color format for c2d (2141391876)
2021-07-22 15:41:19.396 1319-1319/? E/OMX-VDEC-1080P: Setting color format failed
2021-07-22 15:41:19.413 870-870/? E/soundtrigger: audio_extn_sound_trigger_set_parameters: str_params NULL
2021-07-22 15:41:19.425 1319-1319/? E/OMX-VDEC-1080P: Unsupported output color format for c2d (2141391876)
2021-07-22 15:41:19.425 1319-1319/? E/OMX-VDEC-1080P: Setting color format failed
2021-07-22 15:41:20.251 17121-17217/? E/nightwatch-target: /proc/zoneinfo open: errno=13
2021-07-22 15:41:20.251 17121-17217/? E/nightwatch-target: sysmeminfo parse failed
2021-07-22 15:41:21.084 893-7160/? E/sensors-hal: handle_sns_client_event:85, device_orient_event: ts=941099097576, type=0
2021-07-22 15:41:21.898 1789-4085/? E/TaskPersister: File error accessing recents directory (directory doesn't exist?).
2021-07-22 15:41:21.940 1271-1374/? E/statsd: Found dropped events: 1 error -19 last atom tag 83 from uid 10341
2021-07-22 15:41:21.976 4026-4061/? E/hypnusd: same package name, skip
2021-07-22 15:41:22.045 3641-8492/? E/NetworkScheduler.ATC: Called cancelTask for already completed task com.google.android.gms/.measurement.PackageMeasurementTaskServiceu=0 tag="Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG" trigger=windowstart=149s,end=299s,earliest=-550s,latest=-400s requirements=[NET_CONNECTED] attributes=[PERSISTED] scheduled=-699s last_run=-383s exec_window_multiplier=1.0000 jid=N/A status=ACTIVE retries=0 client_lib=GMS_TASK_SCHEDULER-212418000 :1 [CONTEXT service_id=218 ]
2021-07-22 15:41:22.068 1789-1903/? E/WindowManager: App trying to use insecure INPUT_FEATURE_NO_INPUT_CHANNEL flag. Ignoring
2021-07-22 15:41:22.134 919-973/? E/ANDR-PERF-UTIL: Failed to update node /proc/sys/kernel/sched_upmigrate with value 50
2021-07-22 15:41:22.134 919-973/? E/ANDR-PERF-RESOURCEQS: Failed to reset optimization [3, 7]
2021-07-22 15:41:22.144 3641-8492/? E/NetworkScheduler.ATC: Called cancelTask for already completed task com.google.android.gms/.measurement.PackageMeasurementTaskServiceu=0 tag="Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG" trigger=windowstart=149s,end=299s,earliest=-551s,latest=-401s requirements=[NET_CONNECTED] attributes=[PERSISTED] scheduled=-700s last_run=-383s exec_window_multiplier=1.0000 jid=N/A status=ACTIVE retries=0 client_lib=GMS_TASK_SCHEDULER-212418000 :1 [CONTEXT service_id=218 ]
2021-07-22 15:41:22.891 17512-17512/? E/.android.gms.u: Not starting debugger since process cannot load the jdwp agent.
2021-07-22 15:41:25.554 1789-4085/? E/TaskPersister: File error accessing recents directory (directory doesn't exist?).
2021-07-22 15:41:27.812 893-7160/? E/sensors-hal: handle_sns_client_event:85, device_orient_event: ts=947777859428, type=4
2021-07-22 15:41:28.581 1789-5223/? E/WindowManager: App trying to use insecure INPUT_FEATURE_NO_INPUT_CHANNEL flag. Ignoring
2021-07-22 15:41:28.634 4026-17555/? E/hypnusd: same package name, skip
2021-07-22 15:41:28.700 1789-1903/? E/WindowManager: App trying to use insecure INPUT_FEATURE_NO_INPUT_CHANNEL flag. Ignoring
2021-07-22 15:41:28.754 919-973/? E/ANDR-PERF-UTIL: Failed to update node /proc/sys/kernel/sched_upmigrate with value 50
2021-07-22 15:41:28.755 919-973/? E/ANDR-PERF-RESOURCEQS: Failed to reset optimization [3, 7]
2021-07-22 15:41:28.828 3641-14933/? E/NetworkScheduler.ATC: Called cancelTask for already completed task com.google.android.gms/.measurement.PackageMeasurementTaskServiceu=0 tag="Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG" trigger=windowstart=149s,end=299s,earliest=-557s,latest=-407s requirements=[NET_CONNECTED] attributes=[PERSISTED] scheduled=-706s last_run=-390s exec_window_multiplier=1.0000 jid=N/A status=ACTIVE retries=0 client_lib=GMS_TASK_SCHEDULER-212418000 :1 [CONTEXT service_id=218 ]
2021-07-22 15:41:28.847 3641-8492/? E/NetworkScheduler.ATC: Called cancelTask for already completed task com.google.android.gms/.measurement.PackageMeasurementTaskServiceu=0 tag="Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG" trigger=windowstart=149s,end=299s,earliest=-557s,latest=-407s requirements=[NET_CONNECTED] attributes=[PERSISTED] scheduled=-706s last_run=-390s exec_window_multiplier=1.0000 jid=N/A status=ACTIVE retries=0 client_lib=GMS_TASK_SCHEDULER-212418000 :1 [CONTEXT service_id=218 ]
2021-07-22 15:41:29.048 774-17577/? E/ResolverController: No valid NAT64 prefix (100, <unspecified>/0)
2021-07-22 15:41:29.901 17364-17364/com.example.silkenscoops E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.silkenscoops, PID: 17364
    com.google.firebase.database.DatabaseException: Can't convert object of type java.util.ArrayList to type com.example.silkenscoops.Items
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(CustomClassMapper.java:436)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(CustomClassMapper.java:232)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(CustomClassMapper.java:80)
        at com.google.firebase.database.DataSnapshot.getValue(DataSnapshot.java:203)
        at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:29)
        at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:15)
        at com.firebase.ui.common.BaseCachingSnapshotParser.parseSnapshot(BaseCachingSnapshotParser.java:36)
        at com.firebase.ui.common.BaseObservableSnapshotArray.get(BaseObservableSnapshotArray.java:52)
        at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:109)
        at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:149)
        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.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6300)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6296)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2330)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1631)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:668)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4309)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4012)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4578)
        at android.view.View.layout(View.java:22194)
        at android.view.ViewGroup.layout(ViewGroup.java:6366)
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1855)
        at android.view.View.layout(View.java:22194)
        at android.view.ViewGroup.layout(ViewGroup.java:6366)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:22194)
        at android.view.ViewGroup.layout(ViewGroup.java:6366)
        at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:536)
        at android.view.View.layout(View.java:22194)
        at android.view.ViewGroup.layout(ViewGroup.java:6366)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:22194)
        at android.view.ViewGroup.layout(ViewGroup.java:6366)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1845)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:22194)
        at android.view.ViewGroup.layout(ViewGroup.java:6366)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:843)
        at android.view.View.layout(View.java:22194)
2021-07-22 15:41:29.901 17364-17364/com.example.silkenscoops E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:6366)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3427)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2895)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1992)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8203)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1085)
        at android.view.Choreographer.doCallbacks(Choreographer.java:908)
        at android.view.Choreographer.doFrame(Choreographer.java:835)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1070)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:228)
        at android.app.ActivityThread.main(ActivityThread.java:7820)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:981)
2021-07-22 15:41:29.956 1789-2538/? E/InputDispatcher: channel 'ad85a03 com.example.silkenscoops/com.example.silkenscoops.Main (server)' ~ Channel is unrecoverably broken and will be disposed!
2021-07-22 15:41:29.956 1789-2538/? E/InputDispatcher: channel 'a2274e Toast (server)' ~ Channel is unrecoverably broken and will be disposed!
2021-07-22 15:41:29.956 1789-2538/? E/InputDispatcher: channel 'b78fdd2 com.example.silkenscoops/com.example.silkenscoops.loginActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2021-07-22 15:41:29.964 1789-2538/? E/InputDispatcher: channel '2c2077b com.example.silkenscoops/com.example.silkenscoops.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2021-07-22 15:41:30.093 17592-17592/? E/le.silkenscoop: Unknown bits set in runtime_flags: 0x8000
2021-07-22 15:41:30.115 4026-17555/? E/hypnusd: same package name, skip
2021-07-22 15:41:30.489 1789-4787/? E/WindowManager: App trying to use insecure INPUT_FEATURE_NO_INPUT_CHANNEL flag. Ignoring
2021-07-22 15:41:30.521 1789-2120/? E/system_server: Invalid ID 0x00000000.
2021-07-22 15:41:30.601 1789-4787/? E/InputDispatcher: Window handle Window2031ddb u0 android has no registered input channel
2021-07-22 15:41:30.657 3641-14933/? E/NetworkScheduler.ATC: Called cancelTask for already completed task com.google.android.gms/.measurement.PackageMeasurementTaskServiceu=0 tag="Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG" trigger=windowstart=149s,end=299s,earliest=-559s,latest=-409s requirements=[NET_CONNECTED] attributes=[PERSISTED] scheduled=-708s last_run=-392s exec_window_multiplier=1.0000 jid=N/A status=ACTIVE retries=0 client_lib=GMS_TASK_SCHEDULER-212418000 :1 [CONTEXT service_id=218 ]
2021-07-22 15:41:32.126 1789-4085/? E/TaskPersister: File error accessing recents directory (directory doesn't exist?).
2021-07-22 15:41:32.420 895-2622/? E/android.hardware.usb@1.0-service: uevent received SUBSYSTEM=dual_role_usb
2021-07-22 15:41:33.422 8117-17665/? E/memtrack: Couldn't load memtrack module
2021-07-22 15:41:46.438 15771-15974/? E/nightwatch-target: lmkd signal waiters
2021-07-22 15:42:21.673 17726-17726/? E/earme.romupdat: Not starting debugger since process cannot load the jdwp agent.
2021-07-22 15:42:26.929 17750-17750/? E/com.oppo.lfeh: Not starting debugger since process cannot load the jdwp agent.
2021-07-22 15:44:28.907 4914-4949/? E/OpenID: com.nearme.statistics.rom:DUID:ret:T
2021-07-22 15:44:28.911 4914-4949/? E/OpenID: com.nearme.statistics.rom:OUID:ret:T
2021-07-22 15:44:28.914 4914-4949/? E/OpenID: com.nearme.statistics.rom:GUID:ret:T
2021-07-22 15:44:28.917 4914-4949/? E/OpenID: com.nearme.statistics.rom:OUID_STATUS:ret:T
2021-07-22 15:45:17.441 1789-2524/? E/OppoKillerManagerService: o-kill [16929] com.coloros.wirelesssettings
2021-07-22 15:45:57.372 1789-2152/? E/AppIdleHistory: Error writing app idle file for user 0
2021-07-22 15:45:57.391 1789-2152/? E/AppIdleHistory: Error writing app idle file for user 999
2021-07-22 15:46:01.933 17842-17842/? E/ogle.android.g: Not starting debugger since process cannot load the jdwp agent.
2021-07-22 15:46:02.495 17842-17939/? E/arrg: Sync subscriptions not available
2021-07-22 15:46:04.105 17842-17856/? E/DataBuffer: Internal data leak within a DataBuffer object detected!  Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@e1d3467)
2021-07-22 15:46:33.548 8117-17993/? E/memtrack: Couldn't load memtrack module
2021-07-22 15:46:35.658 15771-15974/? E/nightwatch-target: lmkd signal waiters


我的物品类


import com.google.firebase.database.PropertyName;

class Items 
    private String price, stock, product;
    
    public Items() 

    @PropertyName("Price")
    public String getPrice() 
        return price;
    

    public void setPrice(String price) 
        this.price = price;
    

    @PropertyName("Stock")
    public String getStock() 
        return stock;
    

    public void setStock(String stock) 
        this.stock = stock;
    

    @PropertyName("Product")
    public String getProduct() 
        return product;
    

    public void setProduct(String product) 
        this.product = product;
    


清单.XML

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.silkenscoops">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.SilkenScoops">
        <activity android:name=".Main"></activity>
        <activity android:name=".loginActivity"></activity>
        <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    </application>

</manifest>

依赖关系:


dependencies 

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-database:20.0.0'
    testImplementation 'junit:junit:4.+'
    implementation 'com.google.firebase:firebase-analytics'
    implementation platform('com.google.firebase:firebase-bom:28.2.1')
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.firebaseui:firebase-ui-database:7.2.0'
    implementation 'com.google.firebase:firebase-database:19.3.1'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation "androidx.cardview:cardview:1.0.0"

仅供参考:在 Firebase 中授予 Internet 权限的规则适用于读取和写入。 Android Studio 是最新版本。

我的数据库是这样的:。

问题是,当我登录时,它不会显示数据,而是将我拉回登录活动。 似乎查询和所有都不起作用。

【问题讨论】:

有没有崩溃? 嘿..感谢您的关注..是的它崩溃并返回到我的登录活动..logcat没有显示任何错误...如果我删除设置适配器RecyclerView不会崩溃不再只是一个空白的黑屏 drive.google.com/file/d/1khJrlP4ZLxuB8a03tlx8Hm8FApj2S_dt/…(这是应用的视频) 如果应用程序崩溃,会有一个堆栈跟踪。请在 logcat 上查找,并将其添加到您的问题中。 这些都是警告,没有例外。可以再检查一下吗? 【参考方案1】:

您收到以下错误:

com.google.firebase.database.DatabaseException:发现两个 getter 或属性的区分大小写冲突的字段:价格

因为您的items 类中有一个名为Price 的字段,该字段定义为public。这意味着您将能够直接在字段上设置值,而不需要默认提供的 setter。除此之外,默认情况下还会为您提供一个 getter。由于您在班级中明确添加了一个新的 getter:

public String getPrice() 
    return Price;

这意味着您有 重复 个吸气剂。这意味着您的代码中的那个与默认的相冲突,因此出现上述错误。

要解决这个问题,您只需将items 类中的所有属性设置为private。这样,您将告诉编译器只有一个 getter 可用。

即使您进行以下更改:

private String Price;

仍然存在问题。因此,您的代码中的问题在于,您的 items 类中有一个名为 Price 的字段,而您定义的 getter 称为 getPrice(),这是 正确的,因为 Firebase正在数据库中查找名为 price 而不是 Price 的字段。看到小写的p 和大写的P

现在,有两种方法可以解决这个问题。第一个是通过根据Java Naming Conventions 重命名字段来更改您的模型类。所以你的模型类应该是这样的:

class Items 
    private String price, stock, product;
    
    public Items() 

    public String getPrice() 
        return price;
    

    public void setPrice(String price) 
        this.price = price;
    

    public String getStock() 
        return stock;
    

    public void setStock(String stock) 
        this.stock = stock;
    

    public String getProduct() 
        return product;
    

    public void setProduct(String product) 
        this.product = product;
    

在这个例子中,有private 字段(小写)和public getter。除此之外,类名以I大写开头。

还有一个更简单的解决方案,就是直接在公共字段上设置值,类的声明最少,像这样:

class Items 
    public String price, stock, product;

现在只需删除当前数据并使用正确的(小写)名称再次添加它。此解决方案仅在您处于测试阶段时才有效。

还有另一种方法,就是使用“注解”。所以如果你更喜欢使用私有字段和公共getter,你应该在getter前面添加PropertyName注解only。所以你的Items 类应该是这样的:

class Items 
    private String price, stock, product;
    
    public Items() 

    @PropertyName("Price")
    public String getPrice() 
        return price;
    

    @PropertyName("Price")
    public void setPrice(String price) 
        this.price = price;
    

    @PropertyName("Stock")
    public String getStock() 
        return stock;
    

    @PropertyName("Stock")
    public void setStock(String stock) 
        this.stock = stock;
    

    @PropertyName("Product")
    public String getProduct() 
        return product;
    

    @PropertyName("Product")
    public void setProduct(String product) 
        this.product = product;
    

意味着您告诉 Firebase 处理以大写字母开头的字段。

【讨论】:

如果我使用属性,我的适配器类会是什么样子...... get 函数现在给出错误 很可能,除非您使用公共字段,否则您不应在适配器类中执行任何操作。您实施了哪种解决方案? 您推荐哪种解决方案,这样我就可以使用我现有的数据库而无需更改...以 Caps 开头的单词的数据库 很好,所以您在 getter 前面添加了注释,并将字段设置为私有。现在可以用了吗? 不存在崩溃:(

以上是关于FireBase 实时数据库:回收站视图未填充的主要内容,如果未能解决你的问题,请参考以下文章

无法从 firebase 回收器视图中的 firebase 实时数据库中获取嵌套数据

在 Firebase 实时数据库中,我如何遍历每个产品并在回收站视图中显示它们的详细信息

添加数据时,Firebase 列表视图未实时显示

已实现 Firebase 实时数据库存储的 Android 应用中的多个应用内产品

使用 Firebase 数据填充集合视图

我没有在我的Android回收站视图中看到mp3文件名,而是看到了他们的链接