KeyValueX icon indicating copy to clipboard operation
KeyValueX copied to clipboard

使用时报错:ClassNotFoundException & ClassCastException

Open KXwonderful opened this issue 1 year ago • 7 comments

我尝试着集成在项目中测试,在启动 Activity 发现会报 java.lang.ClassNotFoundException: com.xxx.xxx.xxx.ConfigsImpl 的错误,集成使用方式如下:

implementation 'com.github.KunMinX.KeyValueX:keyvalue:3.2.0-beta'
annotationProcessor 'com.github.KunMinX.KeyValueX:keyvalue-compiler:3.2.0-beta'
@KeyValueX
public interface Configs {
    KeyValueBoolean isLogin();
}
public class WelcomeActivity extends AppCompatActivity {

    Configs configs = KeyValueProvider.get(Configs.class); // 这行会报错

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        ...

        LogUtils.wLog().e("isLogin=" + configs.isLogin().get());
        configs.isLogin().set(!configs.isLogin().get());
    }
}

并且 crash: Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to xxx.xxx.xxx.Configs

KXwonderful avatar Aug 26 '22 09:08 KXwonderful