简体   繁体   English

我无法从Firebase检索数据

[英]I cannot retrieve my data from Firebase

This is my Firebase tree: 这是我的Firebase树:

package com.example.android.frep;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;
import java.util.List;

public class fHome extends AppCompatActivity {

List<resepNusantara> listResepNusantara;
ListView listViewResep;

DatabaseReference dbResepNusantara;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_f_home);
    listViewResep = (ListView) findViewById(R.id.resepList);
    dbResepNusantara = FirebaseDatabase.getInstance().getReference("resepNusantara");
}


@Override
protected void onStart() {
    super.onStart();

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

            //clear the list
            //listResepNusantara.clear();

            //iterating all nodes
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                //getting resep
                //This is the ERROR START
                resepNusantara resepN = postSnapshot.getValue(resepNusantara.class);
                //adding resep to the list
                listResepNusantara.add(resepN);
            }

            //creating the adapter for the list
            ResepList resepListAdapter = new ResepList(fHome.this, listResepNusantara);
            //attaching adapter to the listView
            listViewResep.setAdapter(resepListAdapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

}

Hi, everyone I want to ask, i have a problem to retrieve data from firebase 嗨,我想问的每个人,我都无法从Firebase检索数据

In my model class which is resepNusantara, I've tried to change my properties type to Long but it stills error. 在我的模型类resepNusantara中,我尝试将属性类型更改为Long,但仍然出现错误。 The error line is on comment 错误行在评论中

I follow this guidelines: https://www.simplifiedcoding.net/firebase-realtime-database-crud/ 我遵循以下准则: https : //www.simplifiedcoding.net/firebase-realtime-database-crud/

This is the LogCat: 这是LogCat:

10-24 20:35:14.002 18631-18745/com.example.android.frep D/libc-netbsd: [getaddrinfo]:  hostname=frep-ffacb.firebaseio.com;  servname=(null);  app_pid=18631;  app_uid=10161;  ai_flags=1024;  ai_family=0; ai_socktype=1; netid=0; mark=0; from prox result 0
10-24 20:35:14.521 18631-18745/com.example.android.frep E/NativeCrypto: ssl=0x7f93ff4880 cert_verify_callback x509_store_ctx=0x7f6d5889f0 arg=0x0
10-24 20:35:15.610 18631-18631/com.example.android.frep E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.android.frep, PID: 18631
  com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String
      at com.google.android.gms.internal.zzbqi.zzaD(Unknown Source)
      at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
      at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
      at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
      at com.google.android.gms.internal.zzbqi$zza.zze(Unknown Source)
      at com.google.android.gms.internal.zzbqi$zza.zzaG(Unknown Source)
      at com.google.android.gms.internal.zzbqi.zze(Unknown Source)
      at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
      at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
      at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
      at com.example.android.frep.fHome$1.onDataChange(fHome.java:56)
      at com.google.android.gms.internal.zzbmz.zza(Unknown Source)
      at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source)
      at com.google.android.gms.internal.zzboc$1.run(Unknown Source)
      at android.os.Handler.handleCallback(Handler.java:815)
      at android.os.Handler.dispatchMessage(Handler.java:104)
      at android.os.Looper.loop(Looper.java:238)
      at android.app.ActivityThread.main(ActivityThread.java:6006)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:937)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:798)

There is a data type mismatch when marshaling the resepNusantara class. resepNusantara类时,数据类型不匹配。 Specifically, one of the members is stored as a long in the database and string in the class. 具体来说,成员之一在数据库中存储为long ,而在类中存储为string

Dump the object to the console and inspect the database to make sure the types are all synced. 将对象转储到控制台并检查数据库,以确保所有类型都已同步。

See this post for more information: Firebase DatabaseException: Failed to convert value of type java.lang.Long to String 有关更多信息,请参见此文章: Firebase DatabaseException:无法将类型java.lang.Long的值转换为String

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法使用 FirebaseRecyclerAdapter 从 Firebase 数据库中检索我的数据 - I cannot retrieve my data from Firebase Database using my FirebaseRecyclerAdapter 无法将数据从 Firebase 数据库检索到我的 Android 应用程序中 - Cannot Retrieve data from Firebase Database into my Android App 如何将数据从 FireBase 检索到我的适配器而不是关键 - How can I retrieve data from FireBase to my adapter not the key 我无法通过我的应用程序从 firebase 检索动态链接,因为 pendingdynamiclinkdata 为空 - I cannot retrieve dynamic link from firebase through my application as pendingdynamiclinkdata is null 我正在尝试将 firebase 实时数据库中的数据检索到我的 recyclerview 中,但数据显示 null - I am trying to retrieve data from firebase realtime database into my recyclerview but data is showing null 如何从Firebase数据库检索数据以显示标记? - How can I retrieve data from my Firebase Database to display markers? 无法从 Firebase 实时数据库 Android 检索数据 - Cannot retrieve data from Firebase Realtime Database Android 我想将我的 firebase 数据检索到卡列表中,但没有显示任何内容 - I want to retrieve my firebase data into a card list, but not showing anything 从 Firebase 检索多个数据到我的 Android 应用程序 - Retrieve multiple data from Firebase to my Android applciation 如何从Firebase数据库检索所有花瓶? - How do I retrieve all the vases from my Firebase Database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM