2

Intro: I am trying to build an android app that displays info about books (using Google books API).I have recently added firebase to the app. At this moment I can log in or register to the app,I can search for books (with search view) and I have added a button for every book listed in the ListView that is created from the query.I added functionality to the button as it follows: the button (if pressed) should add the current book(in the Listview) to FireBase.

My next step is to retrieve all the books added by users in another activity called CatalogActivity

public class CatalogActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_catalog);
  GridView catalogListView = (GridView) findViewById(R.id.CatalogGridList);

  final List<BookObject> books = new ArrayList<BookObject>();

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference databaseReference = database.getReference();
    databaseReference.child("books").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Iterable<DataSnapshot> children = dataSnapshot.getChildren();
            for (DataSnapshot child : children) {
                BookObject book = child.getValue(BookObject.class);
                books.add(book);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

    CatalogAdapter catalogAdapter = new CatalogAdapter(this, books);
    catalogListView.setAdapter(catalogAdapter);

    }
 }

For better understanding this is the Firebase Data tab: enter image description here

When I run the app and I click on CatalogActivity the app crashes.

I have used debugging with break-points and I got to the following conclusions:

-database instance and reference are obtained correctly

-snapshot of all BookObjects is obtained correctly (dataSnapshot)

-first child snapshot (child) is obtained correctly ( could not tell if the first book is added to books as well)

-pressing F8 again: app jumps to Looper Class at loop method and my app crashes.

What could be causing the app to crash?

Gist of BookObject class:BookObject

Crash log:

07-31 22:40:38.308 15567-15567/com.example.android.booktrade_v10 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                               Process: com.example.android.booktrade_v10, PID: 15567
                                                                               com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: authors
                                                                                   at com.google.android.gms.internal.zh.zzhe(Unknown Source)
                                                                                   at com.google.android.gms.internal.zh.<init>(Unknown Source)
                                                                                   at com.google.android.gms.internal.zg.zzf(Unknown Source)
                                                                                   at com.google.android.gms.internal.zg.zzb(Unknown Source)
                                                                                   at com.google.android.gms.internal.zg.zza(Unknown Source)
                                                                                   at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
                                                                                   at com.example.android.booktrade_v10.CatalogActivity$1.onDataChange(CatalogActivity.java:40)
                                                                                   at com.google.android.gms.internal.to.zza(Unknown Source)
                                                                                   at com.google.android.gms.internal.vj.zzHX(Unknown Source)
                                                                                   at com.google.android.gms.internal.vp.run(Unknown Source)
                                                                                   at android.os.Handler.handleCallback(Handler.java:751)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                   at android.os.Looper.loop(Looper.java:154)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:6316)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

Any help is highly appreciated.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Catalin Ghita
  • 794
  • 8
  • 26

2 Answers2

2

Change your declaration in Plain Old Java Object(POJO) class from

public String Title;
public String Subtitle;
public String Authors;
public String ImageURL;

to this

public String title;
public String subtitle;
public String authors;
public String imageURL;

Let me know if it didn't work.

UmarZaii
  • 1,355
  • 1
  • 17
  • 26
2

What you need to do is to change the names of your fileds with lower case like this:

public String title;
public String subtitle;
public String authors;
public String imageURL;
private String pushId;

Beside that you need to change also all your setters and getters like this:

public String getTitle() {return title;}
public void setTitle(String title) {this.title = title;}

public String getSubtitle() {return subtitle;}
public void setSubtitle(String subtitle) {this.subtitle = subtitle;}

public String getAuthors() {return authors;}
public void setAuthors(String authors) {this.authors = authors;}

public String getImageURL() {return imageURL;}
public void setImageURL(String imageURL) {this.imageURL = imageURL;}

public String getPushId() {return pushId;}
public void setPushId(String pushId) {this.pushId = pushId;}

Cătă, this changes will solve your problem for sure ;)

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193