【问题标题】:Crash without log: toObject没有日志的崩溃:toObject
【发布时间】:2018-04-03 05:52:27
【问题描述】:

我正在尝试将文档映射到自定义类,但应用程序在没有日志的情况下不断崩溃。

我还在学习,所以地图只包含 1 个条目,名为 "pin",值为 "0"

这是代码:

public Response<User> login(LoginRequest request) {
    Task<DocumentSnapshot> task = firestore.collection(NetDatabase.Collections.USERS)
            .document(request.getDni())
            .get();

    DocumentSnapshot document = null;
    try { 
        document = Tasks.await(task); 
    } catch (Exception e) {
        return new Response<>( new Error()); 
    }

    if (document != null && document.exists()){
        User user = document.toObject(User.class); // <-- CRASH
        if (user.getPin().equals(request.getPin())){
            return new Response<>(user);
        }
    }
    return new Response<>(new Error());
}

这是User 类:

public class User extends RealmObject implements NetResponse {

    private String id;
    private String pin;

    public User(){ }

    public User(String pin){
        this.pin = pin;
    }

    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    public String getPin() {
        return pin;
    }
}

public interface NetResponse {
    void setId(String id);
}

我尝试在privatepublic 之间进行交换,但结果保持不变。 document 被正确检索,它包含一个具有上述值的条目。

【问题讨论】:

    标签: android firebase firebase-realtime-database google-cloud-firestore


    【解决方案1】:

    我已经解决了。

    基本上,由于Firestore 正在创建Object,因此使其成为extends RealmObject 可能会产生某种冲突。擦除后,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-13
      • 2020-06-10
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多