Ad

Failed To Convert Value Of Type Java.lang.Double To String

I have tried many solutions this code worked for me in the morning and again when i am running it now it is showing an unknown error here is my user class and I have even tried converting it into doubl also didnt work anyone please help me.

    public class createuser {

    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }

    public String getEmail() {
    return email;
    }

    public void setEmail(String email) {
    this.email = email;
    }

    public String getPassword() {
    return password;
    }

    public void setPassword(String password) {
    this.password = password;
    }

    public String getCode() {
    return code;
    }

    public void setCode(String code) {
    this.code = code;
    }

    public String getIssharing() {
    return issharing;
    }

    public void setIssharing(String issharing) {
    this.issharing = issharing;
    }

    public String getLat() {
    return lat;
    }

    public void setLat(String lat) {
    this.lat = lat;
    }

    public String getLng() {
    return lng;
    }

    public void setLng(String lng) {
    this.lng = lng;
    }

    public String getImgurl() {
    return imgurl;
    }

    public void setImgurl(String imgurl) {
    this.imgurl = imgurl;
    }

    public String getUserid() {
    return userid;
    }

    public void setUserid(String userid) {
    this.userid = userid;
    }

    public createuser() {
    }

    public String name, email, password, code, issharing, lat, lng, 
    imgurl, userid;

    public createuser(String name, String email, String password, String 
    code, String issharing, String lat, String lng, String imgurl, String 
    userid) {
    this.name = name;
    this.email = email;
    this.password = password;
    this.code = code;
    this.issharing = issharing;
    this.lat = lat;
    this.lng = lng;
    this.imgurl = imgurl;
    this.userid = userid;

    }
    }

here is my runtime class

    code = (EditText)findViewById(R.id.editText);
    submit = (Button)findViewById(R.id.button);
    firebaseDatabase = FirebaseDatabase.getInstance();
    auth = FirebaseAuth.getInstance();
    user = auth.getCurrentUser();
    reference = 
          firebaseDatabase.getInstance().getReference().child("users");
    currentreference = 
          firebaseDatabase.getInstance().getReference().child("users")
                      .child(user.getUid());


          current_user_id = user.getUid();

     submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            query = 
     reference.orderByChild("code").equalTo(code.getText().toString());
            query.addListenerForSingleValueEvent
            (new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot 
     dataSnapshot) {
                    if (dataSnapshot.exists())
                    {


                        createuser createuser = null;

                        for (DataSnapshot childDss : 
      dataSnapshot.getChildren())
                        {
                            createuser = 
      childDss.getValue(createuser.class);
                            join_user_id = createuser.userid;

                            circlereference = 
      firebaseDatabase.getInstance().getReference().child("users")

      .child(join_user_id).child("Circlemembers");

                            circlejoin circlejoin = new 
       circlejoin(current_user_id);
                            circlejoin circlejoin1 = new 
        circlejoin(join_user_id);


        circlereference.child(user.getUid()).setValue(circlejoin)
                                    .addOnCompleteListener(new 
        OnCompleteListener<Void>() {
                                        @Override
                                        public void onComplete(@NonNull 
        Task<Void> task) {
                                            if (task.isSuccessful())
                                            {

        Toast.makeText(getApplicationContext(),"user joined 
        circle",Toast.LENGTH_SHORT).show();
                                                startActivity(new 
        Intent(joincircle.this,userlocation.class));
                                            }
                                        }
                                    });


                        }

                    }
                    else
                    {
                        Toast.makeText(getApplicationContext(),"circle 
          code is invalid",Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onCancelled(@NonNull DatabaseError 
         databaseError) {

                }
            });
          }
        });
       } 

Realtime database is like this

    users
    NwKzgM0NhuY7gT7eFiN9nwzumMG2
       code: "7260232"
       email: "[email protected]"
       imgurl: "na"
       issharing: "false"
       lat: 17.3932339
       lng: 78.4440638
       name: "tejesh"
       password: "kinglion"
       userid: "NwKzgM0NhuY7gT7eFiN9nwzumMG2"

anyone please help me i am not able to resolve it my error is

    com.google.firebase.database.DatabaseException: Failed to convert 
     value of type java.lang.Double to String
Ad

Answer

You get the following error:

com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Double to String

Because your lat and lng fields in your createuser class are of type String while in your database both fileds hold a double value and this is not correct. To solve this, simply change the type of your fields in your class to double.

public class createuser {

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getIssharing() {
        return issharing;
    }

    public void setIssharing(String issharing) {
        this.issharing = issharing;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLng() {
        return lng;
    }

    public void setLng(double lng) {
        this.lng = lng;
    }

    public String getImgurl() {
        return imgurl;
    }

    public void setImgurl(String imgurl) {
        this.imgurl = imgurl;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public createuser() {
    }

    public String name, email, password, code, issharing,
            imgurl, userid;
    public double lat, lng;

    public createuser(String name, String email, String password, String
            code, String issharing, double lat, double lng, String imgurl, String
                              userid) {
        this.name = name;
        this.email = email;
        this.password = password;
        this.code = code;
        this.issharing = issharing;
        this.lat = lat;
        this.lng = lng;
        this.imgurl = imgurl;
        this.userid = userid;

    }
}
Ad
source: stackoverflow.com
Ad