[英]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.