获取“未能跳转到类型”异常,即使在提供了准确的firebase引用之后也是如此请查看详细信息

lrl1mhuk  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(160)

我正在开发一个应用程序 Firebase 作为 BaaS .
问题是我越来越 com.firebase.client.FirebaseException: Failed to bounce to type at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183) at com..xyz.MainActivity$2.onDataChange(MainActivity.java:119) 即使给出了正确的火基参考。stacktrace中另一个值得注意的行是 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) .
这里是 Firebase 参考文献: Firebase mFirebaseRef = new Firebase("https://appname.firebaseio.com/users"); 下面是我的代码:

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();
            }

这里是 UsersDataFromFirebase.java 文件代码:

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;
    }

}

作为 Firebase 对我来说是很新鲜的事情,我不知道这里出了什么问题。
请告诉我。
提前谢谢!

euoag5mw

euoag5mw1#

您在java类中包含了一个imageview,但jackson/firebase不知道如何将数据序列化到它。
解决方案是告诉firebase/jackson在从json读取/写入对象时忽略imageview。

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; }
}

请注意,我对这个问题的回答中包含了这一点:当我将firebase中的json转换为java对象时,为什么会出现“无法跳转到type”?

相关问题