Ad

Com.google.firebase.database.DatabaseException: Failed To Convert Value Of Type Java.lang.Double To String

my Blog class is here

package com.nego.lakshan.nego;


public class Blog {

private String FROM;
private String TO;
private String DESCRIPTION;
private String IMAGE;
private String DATE;
private double TOLAT;
private double TOLNG;
private double FROMLAT;
private double FROMLNG;

public Blog(){

}

public Blog(String FROM, String TO, String DESCRIPTION, String IMAGE, String DATE, String TOLAT, String TOLNG, String FROMLAT, String FROMLNG) {
    this.FROM = FROM;
    this.TO = TO;
    this.DESCRIPTION = DESCRIPTION;
    this.IMAGE = IMAGE;
    this.DATE = DATE;
    this.TOLAT = Double.parseDouble(TOLAT);
    this.TOLNG = Double.parseDouble(TOLNG);
    this.FROMLAT = Double.parseDouble(FROMLAT);
    this.FROMLNG = Double.parseDouble(FROMLNG);
}



public String getFROM() {
    return FROM;
}

public void setFROM(String FROM) {
    this.FROM = FROM;
}

public String getTO() {
    return TO;
}

public void setTO(String TO) {
    this.TO = TO;
}

public String getIMAGE() {
    return IMAGE;
}

public void setIMAGE(String IMAGE) {
    this.IMAGE = IMAGE;
}

public String getDATE() {
    return DATE;
}

public void setDATE(String DATE) {
    this.DATE = DATE;
}

public double getTOLAT() {
    return TOLAT;
}

public void setTOLAT(String TOLAT) {
    this.TOLAT = Double.parseDouble(TOLAT);
}

public double getTOLNG() {
    return TOLNG;
}

public void setTOLNG(String TOLNG) {
    this.TOLNG = Double.parseDouble(TOLNG);
}

public double getFROMLAT() {
    return FROMLAT;
}

public void setFROMLAT(String FROMLAT) {
    this.FROMLAT = Double.parseDouble(FROMLAT);
}

public double getFROMLNG() {
    return FROMLNG;
}

public void setFROMLNG(String FROMLNG) {
    this.FROMLNG = Double.parseDouble(FROMLNG);
}


public String getDESCRIPTION() {
    return DESCRIPTION;
}

public void setDESCRIPTION(String DESCRIPTION) {
    this.DESCRIPTION = DESCRIPTION;
}

}

and my Fragment class is use to view the data in recycler view which i get from the runtime database (Firebase). and my fragment class is here

package com.nego.lakshan.nego;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;


import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;




public class RecieverFragment extends Fragment {


public RecieverFragment() {
    // Required empty public constructor
}

private RecyclerView mBlogList;
private DatabaseReference mDatabaseReference;
private View v;

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    v=inflater.inflate(R.layout.fragment_reciever, container, false);


    mBlogList= (RecyclerView) v.findViewById(R.id.fragment);


    mBlogList.setHasFixedSize(true);
    mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("Blog");





    mBlogList.setLayoutManager(new LinearLayoutManager(getContext()));



    Toast.makeText(getContext(),"mmmm",Toast.LENGTH_SHORT).show();
    return v;





}

@Override
public void onStart() {
    super.onStart();
    FirebaseRecyclerAdapter<Blog,BlogViewHolder> 
 mFirebaseRecyclerAdapter=new FirebaseRecyclerAdapter<Blog, BlogViewHolder>
(Blog.class,
            R.layout.blog_item,
            BlogViewHolder.class,
            mDatabaseReference) {
        @Override
        protected void populateViewHolder(BlogViewHolder viewHolder, Blog 
 model, int position) {


            Toast.makeText(getContext(),"maaa",Toast.LENGTH_SHORT).show();


            viewHolder.setDATE(model.getDATE());
            viewHolder.setDESCRIPTION(model.getDESCRIPTION());
            viewHolder.setFROM(model.getFROM());
            viewHolder.setTO(model.getTO());




        }
    };
    mBlogList.setAdapter(mFirebaseRecyclerAdapter);
}

public static class BlogViewHolder extends  RecyclerView.ViewHolder{

    View mView;

    public BlogViewHolder(View itemView) {
        super(itemView);
        mView=itemView;}
    public void setDATE(String DATE){
        TextView date = (TextView) mView.findViewById(R.id.DATE);
        date.setText(DATE);
    }

    public void setDESCRIPTION(String DESCRIPTION){
        TextView desc= (TextView) mView.findViewById(R.id.DESCRIPTION);
        desc.setText(DESCRIPTION);
    }

    public void setFROM(String FROM){
        TextView from = (TextView) mView.findViewById(R.id.FROM);
        from.setText(FROM);
    }

    public void setTO(String TO){
        TextView to = (TextView) mView.findViewById(R.id.TO);
        to.setText(TO);
    }

    }
}

and my fragment layout File

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.nego.lakshan.nego.RecieverFragment"
android:id="@+id/place_holder">

<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fragment">
</android.support.v7.widget.RecyclerView>


</FrameLayout>

and im using CardView for view (blog posts)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="104dp"
android:orientation="horizontal"
android:weightSum="1">

<ImageView
    android:id="@+id/PROFILEPIC"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="1.05" />

<LinearLayout
    android:layout_width="244dp"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/NAME"
        android:layout_width="match_parent"
        android:layout_height="53dp" />

    <TextView
        android:id="@+id/DATE"
        android:layout_width="match_parent"
        android:layout_height="52dp" />
</LinearLayout>

</LinearLayout>



    <TextView
        android:id="@+id/DESCRIPTION"
        android:layout_width="match_parent"
        android:layout_height="164dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="0.16"
            android:weightSum="1">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="From"
                android:layout_weight="0.31" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:text="To"
                android:layout_weight="0.51" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="0.88"
            android:weightSum="1">

            <TextView
                android:id="@+id/FROM"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.41" />

            <TextView
                android:id="@+id/TO"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.19" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <Button
                android:layout_width="109dp"
                android:layout_height="wrap_content"
                android:text="FROMLOCATION"/>
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TOLOCATION"/>


        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:layout_width="164dp"
            android:layout_height="wrap_content"
            android:text="DIrection"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Message"/>
    </LinearLayout>


</LinearLayout>


</android.support.v7.widget.CardView>

and im getting error and the app crashes when i call the fragment

com.nego.lakshan.nego E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: 
com.nego.lakshan.nego, PID: 28426

com.google.firebase.database.DatabaseException: Failed to convert value of 
type java.lang.Double to String
                                                                       at 
com.google.android.gms.internal.zzbqi.zzaD(Unknown Source)
                                                                       at 
com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
                                                                       at 
com.google.android.gms.internal.zzbqi.zza(Unknown Source)
                                                                       at 
com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
                                                                       at 
com.google.android.gms.internal.zzbqi$zza.zze(Unknown Source)
                                                                       at 
com.google.android.gms.internal.zzbqi$zza.zzaG(Unknown Source)
                                                                       at 
com.google.android.gms.internal.zzbqi.zze(Unknown Source)
                                                                       at 
com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
                                                                       at 
com.google.android.gms.internal.zzbqi.zza(Unknown Source)
                                                                       at 
com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
                                                                       at 



com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecycler
Adapter.java:163)
                                                                       at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:152)
                                                                       at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:195)
                                                                       at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6356)
                                                                       at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6389)
                                                                       at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5335)
                                                                       at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5598)
                                                                       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5440)
                                                                       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5436)
                                                                       at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2224)
                                                                       at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1551)
                                                                       at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1511)
                                                                       at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595)
                                                                       at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3583)
                                                                       at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3312)
                                                                       at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1648)
                                                                       at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:343)
                                                                       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
                                                                       at android.view.Choreographer.doCallbacks(Choreographer.java:580)
                                                                       at android.view.Choreographer.doFrame(Choreographer.java:549)
                                                                       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
                                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:135)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5319)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

please, help me on this.

Ad

Answer

I was added some values to test and I forgot to remove them from the firebase realtime database.. And later i realized and deleted them then it worked, thanks

Ad
source: stackoverflow.com
Ad