这是我第一次问这里,所以我需要帮助。
我看到了相关的主题,但它没有解决我的问题。
我在第d.setName(ds.getValue(Dog.class).getName());
行
这是相关代码:
public void getupdates(DataSnapshot dataSnapshot){
dogies.clear();
if (dataSnapshot.getChildren() == null) {
Toast.makeText(c, "No category", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(c, "they are category", Toast.LENGTH_LONG).show();
}
for (DataSnapshot ds : dataSnapshot.getChildren()) {
Dog d = new Dog();
d.setName(ds.getValue(Dog.class).getName());
d.setUrl(ds.getValue(Dog.class).getUrl());
dogies.add(d);
}
if(dogies.size()>0)
{
customAdapter=new CustomAdapter(c, dogies);
listView.setAdapter((ListAdapter) customAdapter);
}else
{
Toast.makeText(c, "No data", Toast.LENGTH_SHORT).show();
}
}
我得到的输出是they are category
和No data
。
这是引用的类Dog
public class Dog {
private String name;
private String url;
public Dog() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
TRAC 02-11 22:33:04.709 1631-1631 / truckstationsa.truckstation E / ActivityThread:无法找到com.google.android.gms.chimera的提供商信息 02-11 22:33:04.727 1631-1648 / truckstationsa.truckstation E / FirebaseInstanceId:Google Play服务缺失或未经正确许可。 02-11 22:33:05.571 1631-1657 / truckstationsa.truckstation E / libEGL:load_driver(/system/lib/egl/libGLES_emulation.so):dlopen failed:library" / system / lib / egl / libGLES_emulation。所以"未找到 02-11 22:33:05.658 1631-1657 / truckstationsa.truckstation E / EGL_emulation:tid 1657:eglSurfaceAttrib(1174):错误0x3009(EGL_BAD_MATCH) 02-11 22:33:05.704 1631-1657 / truckstationsa.truckstation E / EGL_emulation:tid 1657:eglSurfaceAttrib(1174):错误0x3009(EGL_BAD_MATCH) 02-11 22:33:07.072 1631-1631 / truckstationsa.truckstation E / AndroidRuntime:致命异常:主要 流程:truckstationsa.truckstation,PID:1631 com.firebase.client.FirebaseException:无法跳转到键入 在com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:185) 在truckstationsa.truckstation.FirebaseClient.getupdates(FirebaseClient.java:98) 在truckstationsa.truckstation.FirebaseClient $ 1.onChildAdded(FirebaseClient.java:62) 在com.firebase.client.core.ChildEventRegistration.fireEvent(ChildEventRegistration.java:61)
complet类 公共类FirebaseClient {
Context c;
String DB_URL;
ListView listView;
Firebase firebase;
ArrayList<Dog> dogies= new ArrayList<>();
CustomAdapter customAdapter;
public FirebaseClient(Context c, String DB_URL, ListView listView)
{
this.c= c;
this.DB_URL= DB_URL;
this.listView= listView;
Firebase.setAndroidContext(c);
firebase=new Firebase(DB_URL);
}
public void savedata(String name, String url)
{
Dog d= new Dog();
d.setName(name);
d.setUrl(url);
firebase.child("dog").push().setValue(d);
//Toast.makeText(this, "hi", Toast.LENGTH_SHORT).show();
}
public void refreshdata()
{
firebase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
getupdates(dataSnapshot);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
getupdates(dataSnapshot);
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
public void getupdates(DataSnapshot dataSnapshot){
dogies.clear();
if (dataSnapshot.getChildren() == null) {
Toast.makeText(c, "No category", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(c, "they are category", Toast.LENGTH_LONG).show();
}for (DataSnapshot ds : dataSnapshot.getChildren()) {
Dog d = new Dog();
d.setName(ds.getValue(Dog.class).getName());
d.setUrl(ds.getValue(Dog.class).getUrl());
dogies.add(ds.getValue(Dog.class));
}
if(dogies.size()>0)
{
customAdapter=new CustomAdapter(c, dogies);
listView.setAdapter((ListAdapter) customAdapter);
}else
{
Toast.makeText(c, "No data", Toast.LENGTH_SHORT).show();
}
}
}
答案 0 :(得分:0)
您的错误也说:
Google Play services missing or without correct permission.
因此,请添加Google Play服务或设置正确的权限。