I'm beginner in android with firebase,I want to display a table in a listView
. My table poster
contains three fields: image
, status
and username
. I tried this code but I had this error, I searched in stackoverflow but I didn't find this type of error, I think that the problem in the image
field, thanks.
java.lang.NoClassDefFoundError: android/media/Image
at java.lang.Class.getDeclaredFields(Native Method)
at java.lang.Class.getPublicFieldsRecursive(Class.java:846)
at java.lang.Class.getFields(Class.java:829)
at com.google.android.gms.internal.zzbtg$zza.<init>(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzi(Unknown Source)
at com.google.android.gms.internal.zzbtg.zze(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzb(Unknown Source)
at com.google.android.gms.internal.zzbtg.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.example.root.guidetouristique.PosteGestion$1.onChildAdded(PosteGestion.java:36)
at com.google.android.gms.internal.zzbox.zza(Unknown Source)
at com.google.android.gms.internal.zzbqx.zzZV(Unknown Source)
at com.google.android.gms.internal.zzbra$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: android.media.Image
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at java.lang.Class.getDeclaredFields(Native Method)
at java.lang.Class.getPublicFieldsRecursive(Class.java:846)
at java.lang.Class.getFields(Class.java:829)
at com.google.android.gms.internal.zzbtg$zza.<init>(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzi(Unknown Source)
at com.google.android.gms.internal.zzbtg.zze(Unknown Source)
at com.google.android.gms.internal.zzbtg.zzb(Unknown Source)
at com.google.android.gms.internal.zzbtg.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.example.root.guidetouristique.PosteGestion$1.onChildAdded(PosteGestion.java:36)
My code in PosteGestion.java
:
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Post p = dataSnapshot.getValue(Post.class);
if(p!=null){
affichage.add(p);
}
else{
DR=FBD.getReference();
return;
}
}
Post.java
public class Post {
public Image image;
public String userName;
public String imagePost;
public String status ;
public Post(String userName, String imagePost, String status) {
this.userName = userName;
this.imagePost = imagePost;
this.status = status;
}
public Post(Image image, String userName, String imagePost, String status) {
this.image = image;
this.userName = userName;
this.imagePost = imagePost;
this.status = status;
}
public Post(String userName, String status) {
this.userName = userName;
this.status = status;
}
public Post() {
this.image=null;
this.imagePost=null;
this.userName=null;
this.status=null;
}
@Override
public String toString() {
return "Post{" +
"image=" + image +
", userName='" + userName + '\'' +
", imagePost='" + imagePost + '\'' +
", status='" + status + '\'' +
'}';
}
}
Your Post.java
class is referencing the class android.media.Image
. As you can see in the javadoc for Post , it was added in API level 19 (Kit Kat).
Likely what's happening is you're running your code on an emulator or device that is at a lower API level, which means the class is not available.
Is android.media.Image
really what you want to store in your Post object? The Firebase SDK won't be able to load and store that field to the database anyway.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.