无法在firebase中将java.lang.String类型的值转换为int

时间:2018-05-29 05:15:05

标签: android firebase android-recyclerview

我正在开发一个应用程序,它将数据从firebase提取到回收站视图中。 但是我在应用程序运行的onStart中收到错误

这是我收到的错误。

                                                                                                                     

    Failed to convert a value of type java.lang.String to int
at com.google.android.gms.internal.zg.zzb(Unknown Source)
at com.google.android.gms.internal.zg.zza(Unknown Source)
at com.google.android.gms.internal.zg.zzb(Unknown Source)
at com.google.android.gms.internal.zh.zze(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.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:147)
at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:136)
at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:176)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6477)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6510)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5453)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5719)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5558)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5554)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:608)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3694)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3110)
at android.view.View.measure(View.java:19161)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6118)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1275)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:650)
at android.view.View.measure(View.java:19161)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1630)
at android.view.View.measure(View.java:19161)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6118)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784)
at android.view.View.measure(View.java:19161)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6118)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:19161)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6118)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
at android.view.View.measure(View.java:19161)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6118)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at android.view.View.measure(View.java:19161)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6118)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
at android.widget.LinearLayout.measureVer

StreetDataFetcher.java

这是一个类,用于检索包含所有getter,构造函数的数据。

public class StreetDataFetcher {

     private String UserName;
     private String Long_Desc;
     private String Short_Desc;
     private String DateTime;
     private String VideoName;
     private String VideoPath;
     private String ProfileImage;
     private int  Likes;
     private int Views;

    public StreetDataFetcher( String userName, String long_Desc, String short_Desc, String dateTime, String videoName, String videoPath, String profileImage, int likes, int views ) {
        UserName = userName;
        Long_Desc = long_Desc;
        Short_Desc = short_Desc;
        DateTime = dateTime;
        VideoName = videoName;
        VideoPath = videoPath;
        ProfileImage = profileImage;
        Likes = likes;
        Views = views;
    }

    public int getLikes() {
        return Likes;
    }

    public int getViews() {
        return Views;
    }

    public StreetDataFetcher() {

    }

    public StreetDataFetcher( String profileImage ) {
        ProfileImage = profileImage;
    }

    public String getProfileImage() {
        return ProfileImage;
    }

    public String getUserName() {
        return UserName;
    }

    public void setUserName( String userName ) {
        UserName = userName;
    }

    public String getVideoName() {
        return VideoName;
    }

    public void setVideoName( String videoName ) {
        VideoName = videoName;
    }

    public String getVideoPath() {
        return VideoPath;
    }

    public void setVideoPath( String videoPath ) {
        VideoPath = videoPath;
    }

    public String getLong_Desc() {
        return Long_Desc;
    }

    public void setLong_Desc( String long_Desc ) {
        Long_Desc = long_Desc;
    }

    public String getShort_Desc() {
        return Short_Desc;
    }

    public void setShort_Desc( String short_Desc ) {
        Short_Desc = short_Desc;
    }

    public String getDateTime() {
        return DateTime;
    }

    public void setDateTime( String DateTime ) {
        DateTime = DateTime;
    }


}

ViewHolder

    public static class StreetViewHolder extends RecyclerView.ViewHolder
    {
        TextView Username;
        TextView datee;
        TextView Title;
        TextView ShortDesc;
        ImageView Img1;
        Context ctx;
        de.hdodenhof.circleimageview.CircleImageView Img2;

        public StreetViewHolder( View itemView ) {
            super(itemView);
            ctx=itemView.getContext();
            Username=(TextView)itemView.findViewById(R.id.UsernameText);
            datee=(TextView)itemView.findViewById(R.id.date);
            Title=(TextView)itemView.findViewById(R.id.Title);
            ShortDesc=(TextView)itemView.findViewById(R.id.ShortDescription);
            Img1=(ImageView)itemView.findViewById(R.id.VideoName);
            Img2=(de.hdodenhof.circleimageview.CircleImageView)itemView.findViewById(R.id.ProfilePicture);
        }

        public void setTitle( String title ) {
            Title.setText(title);
        }


        public void setShortDesc( String shortDesc ) {
            ShortDesc.setText(shortDesc);
        }

        public void setUsername( String username ) {
            Username.setText(username);
        }


        public void setDate( String date ) {
            datee.setText(date.toString());
        }

        public void setVideoPath( String videoPath ) {
                MediaMetadataRetriever mediaMetadataRetriever=new MediaMetadataRetriever();
                mediaMetadataRetriever.setDataSource(videoPath,new HashMap<String,String>());
                Bitmap bitmap=mediaMetadataRetriever.getFrameAtTime(10000000);
                Img1.setImageBitmap(bitmap);
        }

        public void setProfile( String profile ) {
            Picasso.with(ctx).load(profile).into(Img2);        }
    }

RecyclerView

myRef1 = FirebaseDatabase.getInstance().getReference().child("Video_Upload").child("Street");
                myRef1.keepSynced(true);
                myRef1.orderByKey();
                rView = (RecyclerView) rootView.findViewById(R.id.StreetRecyclerView);
                rView.hasFixedSize();
                RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
                rView.setLayoutManager(layoutManager);
                FBRA = new FirebaseRecyclerAdapter<StreetDataFetcher, Street_food.StreetViewHolder>(
                        StreetDataFetcher.class,
                        R.layout.card_recycler_view,
                        Street_food.StreetViewHolder.class,
                        myRef1
                ) {
                    @Override
                    protected void populateViewHolder( Street_food.StreetViewHolder viewHolder, StreetDataFetcher model, final int position ) {
                        viewHolder.setTitle(model.getVideoName());
                        viewHolder.setShortDesc(model.getShort_Desc());
                        viewHolder.setUsername(model.getUserName());
                        viewHolder.setDate(model.getDateTime());
                        viewHolder.setVideoPath(model.getVideoPath());
                        viewHolder.setProfile(model.getProfileImage());
                        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick( View v ) {
                                final String mref;
                                mref=FBRA.getRef(position).getKey().toString().trim();
                                Intent i=new Intent(getActivity(),StreetVideoView.class);
                                i.putExtra("position",mref);
                                startActivity(i);

                            }
                        });
                    }
                };

                rView.setAdapter(FBRA);
                

Firebase结构

firebase Structure

0 个答案:

没有答案