0

I'm developing an app which is using Firebase as BaaS.

The problem is that I'm getting com.firebase.client.FirebaseException: Failed to bounce to type at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183) at com.abc.xyz.MainActivity$2.onDataChange(MainActivity.java:119) even after giving the right firebase reference. Another notable line in the stacktrace is Caused by: com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "colorFilter": android.widget.ImageView#setColorFilter(1 params) vs android.widget.ImageView#setColorFilter(1 params).

Here's Firebase reference: Firebase mFirebaseRef = new Firebase("https://appname.firebaseio.com/users");

Here's my piece of code:

    mFirebaseRef.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot snapshot) {
                        System.out.println("There are " + snapshot.getChildrenCount() + " blog posts");
                        for (DataSnapshot postSnapshot : snapshot.getChildren()) {
    //error on this line 
UsersDataFromFirebase post = postSnapshot.getValue(UsersDataFromFirebase.class);

                            View nameView = navigationView.getHeaderView(0);
                            userName = (TextView) nameView.findViewById(R.id.userName);
                            userName.setText(post.getUserName());

                            System.out.println(post.getUserName());
                            System.out.println(post.getUserEmail());

    //                        View emailView = navigationView.getHeaderView(0);
    //                        userEmail = (TextView) emailView.findViewById(R.id.userEmail);
    //                        userEmail.setText();

                            userImageUrl = (URL) authData.getProviderData().get("profileImageUrl");

                            String userImageUrlString = userImageUrl.toString();

                            URL url = null;
                            try {
                                url = new URL(userImageUrlString);
                            } catch (MalformedURLException e) {
                                e.printStackTrace();
                            }
                            try {
                                image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                            View imageView = navigationView.getHeaderView(0);
                            userImage = (ImageView) imageView.findViewById(R.id.userImage);
                            userImage.setImageBitmap(image);

                        }
                    }

                    @Override
                    public void onCancelled(FirebaseError firebaseError) {
                        System.out.println("The read failed: " + firebaseError.getMessage());
                        Toast.makeText(getBaseContext(), firebaseError.getMessage(), Toast.LENGTH_LONG).show();
                    }
                });

            } else {
                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(MainActivity.this);
                builder.setTitle("No internet connection!");
                builder.setMessage("Please connect to the internet.");
                builder.setPositiveButton("Open Settings", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Intent intent = new Intent(Settings.ACTION_SETTINGS);
                        startActivity(intent);
                        //progressBar.setVisibility(View.INVISIBLE);
                    }
                });
                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //progressBar.setVisibility(View.INVISIBLE);
                    }
                });
                builder.show();
            }

Here's UsersDataFromFirebase.java file's code:

public class UsersDataFromFirebase {
    private String userName;
    private String userEmail;
    private ImageView userImage;

    public UsersDataFromFirebase() {
        // empty default constructor, necessary for Firebase to be able to deserialize blog posts
    }

    public String getUserName() {
        return userName;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public ImageView getUserImage() {
        return userImage;
    }

}

As Firebase is something very new to me, I'm unable to figure out what's going wrong here.

Please let me know.

Thanks in advance!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • What line in your code is MainActivity.java:119? Also: add a snippet of your JSON, which you can easily get by clicking the Export button in your Firebase dashboard. – Frank van Puffelen Mar 28 '16 at 04:18
  • @FrankvanPuffelen I have mentioned the line on which I'm getting the error. Snippet of JSON: `{ "users" : { "20fb1a2a-5658-4b36-af28-c807dc6b187a" : { "userEmail" : "hns.billion@gmail.com", "userName" : "Hammad Nasir" } } }` –  Mar 28 '16 at 06:21
  • @FrankvanPuffelen please respond... –  Mar 28 '16 at 18:15

1 Answers1

0

You've included a ImageView in your Java class, which Jackson/Firebase doesn't know how to serialize data to.

The solution is to tell Firebase/Jackson to ignore the ImageView when it reads the object from/writes it to JSON.

public class UsersDataFromFirebase {
    private String userName;
    private String userEmail;
    private ImageView userImage;

    public UsersDataFromFirebase() {
        // empty default constructor, necessary for Firebase to be able to deserialize blog posts
    }

    public String getUserName() { return userName; }

    public String getUserEmail() { return userEmail; }

    @JsonIgnore    
    public ImageView getUserImage() { return userImage; }
}

Note that this is covered in my answer to this question: Why do I get "Failed to bounce to type" when I turn JSON from Firebase into Java objects?

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • can you please answer this too: http://stackoverflow.com/questions/36353638/unable-to-fetch-users-gmail-email-address-through-firebase –  Apr 01 '16 at 10:27