DatabaseException:无法将java.lang.String类型的对象转换为android类型

时间:2018-10-11 13:35:54

标签: android firebase firebase-realtime-database firebaseui

这是错误:

 E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.md.HeartOpen, PID: 31667
              com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.md.HeartOpen.File_Setings.Spacecraft
                  at com.google.android.gms.internal.zzelw.zzb(Unknown Source:259)
                  at com.google.android.gms.internal.zzelw.zza(Unknown Source:0)
                  at com.google.firebase.database.DataSnapshot.getValue(Unknown Source:10)
                  at com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:151)
                  at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:140)
                  at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:183)
                  at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6673)
                  at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6714)
                  at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5647)
                  at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5913)
                  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
                  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
                  at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
                  at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
                  at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
                  at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
                  at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
                  at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
                  at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
                  at android.view.View.layout(View.java:19781)
                  at android.view.ViewGroup.layout(ViewGroup.java:6144)
                  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1816)
                  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1660)
                  at android.widget.LinearLayout.onLayout(LinearLayout.java:1569)
                  at android.view.View.layout(View.java:19781)
                  at android.view.ViewGroup.layout(ViewGroup.java:6144)
                  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
                  at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
                  at android.view.View.layout(View.java:19781)
                  at android.view.ViewGroup.layout(ViewGroup.java:6144)
                  at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443)
                  at android.view.View.layout(View.java:19781)
                  at android.view.ViewGroup.layout(ViewGroup.java:6144)
                  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
                  at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
                  at android.view.View.layout(View.java:19781)
                  at android.view.ViewGroup.layout(ViewGroup.java:6144)
                  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1816)
                  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1660)
                  at android.widget.LinearLayout.onLayout(LinearLayout.java:1569)
                  at android.view.View.layout(View.java:19781)
                  at android.view.ViewGroup.layout(ViewGroup.java:6144)
                  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
                  at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
                  at com.android.internal.policy.DecorView.onLayout(DecorView.java:888)
                  at android.view.View.layout(View.java:19781)
                  at android.view.ViewGroup.layout(ViewGroup.java:6144)
                  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2674)
                  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2377)
                  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1515)
                  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7266)
                  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:981)
                  at android.view.Choreographer.doCallbacks(Choreographer.java:790)
E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:721)
                  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:967)
                  at android.os.Handler.handleCallback(Handler.java:808)
                  at android.os.Handler.dispatchMessage(Handler.java:101)
                  at android.os.Looper.loop(Looper.java:166)
                  at android.app.ActivityThread.main(ActivityThread.java:7425)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

这是我的活动

public class SizeLikesPostActivity extends AppCompatActivity {

    //Firebase
    private DatabaseReference mDatabase ;
    private DatabaseReference mDatabaseUser ;
    private FirebaseAuth mAuthh ;

    private RecyclerView mMainList ;
    private LinearLayoutManager linearLayoutManager ;
    private String name_user , image_user , status_user;
    private String currentUserId ;
    private String post_key ,user_key;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //left to right
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
        }
        setContentView(R.layout.size_likes_post);


        user_key = getIntent().getStringExtra("USER_KEY");
        post_key = getIntent().getStringExtra("Post_Key");


        mDatabase = FirebaseDatabase.getInstance().getReference().child("Likes").child(post_key);
        mDatabase.keepSynced(true); //Oflline Data


        //RecycleView
        mMainList = (RecyclerView)findViewById(R.id.recycleView);
        mMainList.setHasFixedSize(true);


        //GetItem new First
        linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setReverseLayout(true);
        linearLayoutManager.setStackFromEnd(true);
        mMainList.setLayoutManager(linearLayoutManager);


    }

    @Override
    protected void onStart() {
        super.onStart();

        FirebaseRecyclerAdapter<Spacecraft , SizeLikesHolder> firebaseRecyclerAdapter
                = new FirebaseRecyclerAdapter<Spacecraft, SizeLikesHolder>(
                Spacecraft.class,
                R.layout.row_size_likes,
                SizeLikesHolder.class,
                mDatabase
        ) {
            @Override
            protected void populateViewHolder(SizeLikesHolder viewHolder, Spacecraft model, int position) {
                final String id_comment = getRef(position).getKey();



              //  viewHolder.setTitle(name, desc, time, image );

            }
        };
        mMainList.setAdapter(firebaseRecyclerAdapter);
    }

    public static class SizeLikesHolder extends RecyclerView.ViewHolder{
        View mView;
        Context context ;

        public TextView textName , textComment , timeText ;
        public CircleImageView imageUser ;

        public SizeLikesHolder(View itemView) {
            super(itemView);
            mView = itemView;

            textName = (TextView)mView.findViewById(R.id.uid_user);
            textComment = (TextView)mView.findViewById(R.id.txt_status);
            imageUser = (CircleImageView)mView.findViewById(R.id.imageUser);


            //Chnage font...
            Typeface regular= Typeface.createFromAsset(itemView.getContext().getAssets(),"NizarCoconKurdishRegular.ttf");
            Typeface face= Typeface.createFromAsset(itemView.getContext().getAssets(),"NizarCoconKurdish_Bold.otf");
            textName.setTypeface(face);
            textComment.setTypeface(regular);

        }

        public void setTitle(String name , String status , final String image){

            textName.setText(name);
            textComment.setText(status);

            //Imgae Post if null set Visibtly Gone to ImageView
            if (TextUtils.isEmpty(image)){
                Picasso.with(context).load(R.drawable.default_avatar).into(imageUser);
            }else {
                //Image Post
                Picasso.with(context).load(image).networkPolicy(NetworkPolicy.OFFLINE)
                        .placeholder(R.drawable.default_avatar).into(imageUser , new Callback() {
                    @Override
                    public void onSuccess() {
                        imageUser.setVisibility(View.VISIBLE);
                    }
                    @Override
                    public void onError() {
                        imageUser.setVisibility(View.GONE);
                    }
                }); }


        }
    }
}

0 个答案:

没有答案