无法将java.lang.String类型的值转换为double

无法将java.lang.String类型的值转换为double,java,android,firebase,Java,Android,Firebase,大家好,我是android开发的新手。回顾我的编码,我想将firebase的输出打印到显示所有数据的卡片视图中,但当我从firebase创建具有不同类型值(如字符串和双值)的类模型时,它无法转换。为什么会出现这样的问题?我也希望解决方案 我尝试的是使用Datasnapshot从firebase获取数据,并将字符串值转换为双精度值 火基: firebase看起来像。“> 函数来检索该值 { @Override public void

大家好,我是android开发的新手。回顾我的编码,我想将
firebase
的输出打印到显示所有数据的卡片视图中,但当我从
firebase
创建具有不同类型值(如字符串和双值)的类模型时,它无法转换。为什么会出现这样的问题?我也希望解决方案

我尝试的是使用
Datasnapshot
firebase
获取数据,并将字符串值转换为双精度值

火基:

firebase看起来像。“>

函数来检索该值

        {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot)
            {
                lrpModels =new ArrayList<>();
                for (DataSnapshot postSnapshot : dataSnapshot.getChildren())
                {
                    //the problem at this line
                    LRP_model lrpC = postSnapshot.getValue(LRP_model.class);
                    lrpModels.add(lrpC);
                }
                //creating adapter
                mLRPAdapter = new LRPAdapter(getApplication(),lrpModels, "LRP");
                //add the adapter to the recyclerview
                recyclerView.setAdapter(mLRPAdapter);
            }

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

            }
        });
{
@凌驾
public void onDataChange(@NonNull DataSnapshot DataSnapshot)
{
lrpModels=newarraylist();
对于(DataSnapshot postSnapshot:DataSnapshot.getChildren())
{
//这条线上的问题
LRP_model lrpC=postSnapshot.getValue(LRP_model.class);
lrpModels.add(lrpC);
}
//创建适配器
mLRPAdapter=newlrpadapter(getApplication(),lrpModels,“LRP”);
//将适配器添加到recyclerview
recyclerView.setAdapter(mLRPAdapter);
}
@凌驾
已取消的公共void(@NonNull DatabaseError DatabaseError){
}
});
模范班


    private String uid;
    private String lrpName;
    private String lrpDesc;
    private String lrpStartpoint;
    double lrpSLat;
    double lrpSLng;
    private String lrpEndpoint;
    double lrpELat;
    double lrpELng;
    private String lrpDistance;
    private String lrpSubRegion;
    private String lrpRegion;
    private String userId;
    private ArrayList<Route_model> route_models;

    public LRP_model(){}
    public LRP_model(String uid, String lrpName, String lrpDesc, String lrpStartpoint, double lrpSLat, double lrpSLng, String lrpEndpoint, double lrpELat, double lrpELng, String lrpDistance, String lrpSubRegion, String lrpRegion, String userId, ArrayList<Route_model>route_models) {
        this.uid = uid;
        this.lrpName = lrpName;
        this.lrpDesc = lrpDesc;
        this.lrpStartpoint = lrpStartpoint;
        this.lrpSLat = lrpSLat;
        this.lrpSLng = lrpSLng;
        this.lrpEndpoint = lrpEndpoint;
        this.lrpELat = lrpELat;
        this.lrpELng = lrpELng;
        this.lrpDistance = lrpDistance;
        this.lrpSubRegion = lrpSubRegion;
        this.lrpRegion = lrpRegion;
        this.userId = userId;
        this.route_models = route_models;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public void setLrpName(String lrpName) {
        this.lrpName = lrpName;
    }

    public void setLrpDesc(String lrpDesc) {
        this.lrpDesc = lrpDesc;
    }

    public void setLrpStartpoint(String lrpStartpoint) {
        this.lrpStartpoint = lrpStartpoint;
    }

    public void setLrpSLat(double lrpSLat) {
        this.lrpSLat = lrpSLat;
    }

    public void setLrpSLng(double lrpSLng) {
        this.lrpSLng = lrpSLng;
    }

    public void setLrpEndpoint(String lrpEndpoint) {
        this.lrpEndpoint = lrpEndpoint;
    }

    public void setLrpELat(double lrpELat) {
        this.lrpELat = lrpELat;
    }

    public void setLrpELng(double lrpELng) {
        this.lrpELng = lrpELng;
    }

    public void setLrpDistance(String lrpDistance) {
        this.lrpDistance = lrpDistance;
    }

    public void setLrpSubRegion(String lrpSubRegion) {
        this.lrpSubRegion = lrpSubRegion;
    }

    public void setLrpRegion(String lrpRegion) {
        this.lrpRegion = lrpRegion;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUid() {
        return uid;
    }

    public String getLrpName() {
        return lrpName;
    }

    public String getLrpDesc() {
        return lrpDesc;
    }

    public String getLrpStartpoint() {
        return lrpStartpoint;
    }

    public double getLrpSLat() {
        return lrpSLat;
    }

    public double getLrpSLng() {
        return lrpSLng;
    }

    public String getLrpEndpoint() {
        return lrpEndpoint;
    }

    public double getLrpELat() {
        return lrpELat;
    }

    public double getLrpELng() {
        return lrpELng;
    }

    public String getLrpDistance() {
        return lrpDistance;
    }

    public String getLrpSubRegion() {
        return lrpSubRegion;
    }

    public String getLrpRegion() {
        return lrpRegion;
    }

    public String getUserId() {
        return userId;
    }

    public ArrayList<Route_model> getRoute_models(){
        return  route_models;
    }

    public void setRoute_models(ArrayList<Route_model> route_models){
        this.route_models = route_models;
    }

}

私有字符串uid;
私有字符串lrpName;
专用字符串lrpDesc;
专用字符串lrpStartpoint;
双lrpSLat;
双lrpSLng;
私有字符串点;
双lrpELat;
双lrpleng;
私有字符串lrpDistance;
私有字符串lrpSubRegion;
私有字符串预处理;
私有字符串用户标识;
私有ArrayList路由模型;
公共LRP_模型(){}
公共LRP_模型(字符串uid、字符串lrpName、字符串lrpDesc、字符串lrpStartpoint、双lrpSLat、双lrpSLng、字符串lrpEndpoint、双lrpELat、双LRPELING、字符串lrpDistance、字符串lrpSubRegion、字符串lrpRegion、字符串userId、ArrayListroute_模型){
this.uid=uid;
this.lrpName=lrpName;
this.lrpDesc=lrpDesc;
this.lrpStartpoint=lrpStartpoint;
this.lrpSLat=lrpSLat;
此参数为.lrpSLng=lrpSLng;
this.lrpEndpoint=lrpEndpoint;
this.lrpELat=lrpELat;
this.lrpELng=lrpELng;
this.lrpDistance=lrpDistance;
this.lrpusubregion=lrpusubregion;
this.lrpRegion=lrpRegion;
this.userId=userId;
this.route_models=route_models;
}
公共void setUid(字符串uid){
this.uid=uid;
}
公共void setLrpName(字符串lrpName){
this.lrpName=lrpName;
}
公共无效集合lrpDesc(字符串lrpDesc){
this.lrpDesc=lrpDesc;
}
公共无效设置lrpStartpoint(字符串lrpStartpoint){
this.lrpStartpoint=lrpStartpoint;
}
公共无效设置lrpSLat(双lrpSLat){
this.lrpSLat=lrpSLat;
}
公共空间设置lrpSLng(双lrpSLng){
此参数为.lrpSLng=lrpSLng;
}
公共void setlPendPoint(字符串lPendPoint){
this.lrpEndpoint=lrpEndpoint;
}
公共空间设置lrpELat(双lrpELat){
this.lrpELat=lrpELat;
}
公共无效设置lrpleng(双lrpleng){
this.lrpELng=lrpELng;
}
public void setLrpDistance(字符串lrpDistance){
this.lrpDistance=lrpDistance;
}
公共无效设置lrpSubRegion(字符串lrpSubRegion){
this.lrpusubregion=lrpusubregion;
}
公共void setLrpRegion(字符串lrpRegion){
this.lrpRegion=lrpRegion;
}
public void setUserId(字符串userId){
this.userId=userId;
}
公共字符串getUid(){
返回uid;
}
公共字符串getLrpName(){
返回lrpName;
}
公共字符串getLrpDesc(){
返回lrpDesc;
}
公共字符串getLrpStartpoint(){
返回lrpStartpoint;
}
公共双getLrpSLat(){
返回lrpSLat;
}
公共双getLrpSLng(){
返回lrpSLng;
}
公共字符串getLrpEndpoint(){
返回点;
}
公共双getLrpELat(){
返回lrpELat;
}
公共双getLrpELng(){
返回lrpELng;
}
公共字符串getLrpDistance(){
返回LRP距离;
}
公共字符串getlrpusubregion(){
返回lrpSubRegion;
}
公共字符串getLrpRegion(){
回归预测;
}
公共字符串getUserId(){
返回用户标识;
}
公共阵列列表getRoute_models(){
返回路径模型;
}
公共void setRoute_模型(ArrayList route_模型){
this.route_models=route_models;
}
}
我希望将该值检索为双精度,并可用于将lat和long放入映射,但显示的错误无法转换字符串值。

检查
后发现您已将双精度作为数据类型。将其更改为字符串以获取

double lrpSLat;  change to String lrpSLat;
double lrpSLng;  change to String lrpSLng;
double lrpELat;  change to String lrpELat;
double lrpELng;  change to String lrpELng;
您更新的LRP\U型号将

package com.prime_components; public class LRP_model implements Serializable {
    private String uid;
    private String lrpName;
    private String lrpDesc;
    private String lrpStartpoint;
    String lrpSLat;
    String lrpSLng;
    private String lrpEndpoint;
    String lrpELat;
    String lrpELng;
    private String lrpDistance;
    private String lrpSubRegion;
    private String lrpRegion;
    private String userId;
    private ArrayList<Route_model> route_models;

    public LRP_model(){}
    public LRP_model(String uid, String lrpName, String lrpDesc, String lrpStartpoint, String lrpSLat, String lrpSLng, String lrpEndpoint, String lrpELat, String lrpELng, String lrpDistance, String lrpSubRegion, String lrpRegion, String userId, ArrayList<Route_model>route_models) {
        this.uid = uid;
        this.lrpName = lrpName;
        this.lrpDesc = lrpDesc;
        this.lrpStartpoint = lrpStartpoint;
        this.lrpSLat = lrpSLat;
        this.lrpSLng = lrpSLng;
        this.lrpEndpoint = lrpEndpoint;
        this.lrpELat = lrpELat;
        this.lrpELng = lrpELng;
        this.lrpDistance = lrpDistance;
        this.lrpSubRegion = lrpSubRegion;
        this.lrpRegion = lrpRegion;
        this.userId = userId;
        this.route_models = route_models;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public void setLrpName(String lrpName) {
        this.lrpName = lrpName;
    }

    public void setLrpDesc(String lrpDesc) {
        this.lrpDesc = lrpDesc;
    }

    public void setLrpStartpoint(String lrpStartpoint) {
        this.lrpStartpoint = lrpStartpoint;
    }

    public void setLrpSLat(String lrpSLat) {
        this.lrpSLat = lrpSLat;
    }

    public void setLrpSLng(String lrpSLng) {
        this.lrpSLng = lrpSLng;
    }

    public void setLrpEndpoint(String lrpEndpoint) {
        this.lrpEndpoint = lrpEndpoint;
    }

    public void setLrpELat(String lrpELat) {
        this.lrpELat = lrpELat;
    }

    public void setLrpELng(String lrpELng) {
        this.lrpELng = lrpELng;
    }

    public void setLrpDistance(String lrpDistance) {
        this.lrpDistance = lrpDistance;
    }

    public void setLrpSubRegion(String lrpSubRegion) {
        this.lrpSubRegion = lrpSubRegion;
    }

    public void setLrpRegion(String lrpRegion) {
        this.lrpRegion = lrpRegion;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUid() {
        return uid;
    }

    public String getLrpName() {
        return lrpName;
    }

    public String getLrpDesc() {
        return lrpDesc;
    }

    public String getLrpStartpoint() {
        return lrpStartpoint;
    }

    public String getLrpSLat() {
        return lrpSLat;
    }

    public String getLrpSLng() {
        return lrpSLng;
    }

    public String getLrpEndpoint() {
        return lrpEndpoint;
    }

    public String getLrpELat() {
        return lrpELat;
    }

    public String getLrpELng() {
        return lrpELng;
    }

    public String getLrpDistance() {
        return lrpDistance;
    }

    public String getLrpSubRegion() {
        return lrpSubRegion;
    }

    public String getLrpRegion() {
        return lrpRegion;
    }

    public String getUserId() {
        return userId;
    }

    public ArrayList<Route_model> getRoute_models(){
        return  route_models;
    }

    public void setRoute_models(ArrayList<Route_model> route_models){
        this.route_models = route_models;
    }

}
package com.prime_组件;公共类LRP_模型实现可序列化{
私有字符串uid;
私有字符串lrpName;
专用字符串lrpDesc;
专用字符串lrpStartpoint;
字符串lrpSLat;
管柱lrpSLng;
私有字符串点;
字符串lrpELat;
弦线;
私有字符串lrpDistance;
私有字符串lrpSubRegion;
私有字符串预处理;
私有字符串用户标识;
私有ArrayList路由模型;
公共LRP_模型(){}
公共LRP_模型(字符串uid、字符串lrpName、字符串lrpDesc、字符串lrpStartpoint、字符串lrpSLat、字符串lrpSLng、字符串lrpEndpoint、字符串lrpELat、字符串LRPELING、字符串lrpDistance、字符串lrpSubRegion、字符串lrpRegion、字符串userId、ArrayListroute_模型){
this.uid=uid;
T