ProGuard 块构造函数

问题描述

我正在尝试禁用 ProgUard,因为它阻止了我的活动构造函数。这是构造函数

public ChatFragmentAdapter(Context context,List<Users> user,boolean isChat) {
    this.context = context;
    this.user = user;
    this.isChat = isChat;
}

这是显示错误

com.google.firebase.database.DatabaseException: Class com.example.selfcial.Models.Chat does not define a no-argument constructor. If you are using ProGuard,make sure these constructors are not stripped.
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:570)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:563)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(CustomClassMapper.java:433)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializetoClass(CustomClassMapper.java:232)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(CustomClassMapper.java:80)
        at com.google.firebase.database.DataSnapshot.getValue(DataSnapshot.java:203)
        at com.example.selfcial.Adapters.ChatFragmentAdapter$2.onDataChange(ChatFragmentAdapter.java:154)
        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
        at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
        at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7562)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

我尝试在 Gradle 中添加 useProguard false,但没有任何改变。我该怎么做才能解决这个烦人的错误?我应该删除 ProGuard 的整个文件吗?

解决方法

看来你走错了路。尽管异常消息提到了 ProGuard,但消息的第一部分解释了问题:Class com.example.selfcial.Models.Chat 没有定义无参数构造函数

向您的类 Chat 添加无参数构造函数应该可以解决它:

public Chat() {}