最近几天,我开始在三星设备os 7.0上发生此崩溃。
每当某些api尝试创建新字符串时,都会引发异常,

Fatal Exception: java.lang.UnsupportedOperationException: Use StringFactory instead.
       at java.lang.String.(String.java:176)
       at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serializedName(CustomClassMapper.java:807)
       at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.propertyName(CustomClassMapper.java:775)
       at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.(com.google.firebase:firebase-database@@16.0.4:461)
       at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(CustomClassMapper.java:317)
       at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(CustomClassMapper.java:418)


要么

Caused by java.lang.UnsupportedOperationException: Use StringFactory instead.
       at java.lang.String.(String.java:201)
       at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1001)
       at com.google.gson.stream.JsonReader.nextName(JsonReader.java:787)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:217)
       at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
       at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72)
       at com.google.gson.Gson.fromJson(Gson.java:922)
       at com.google.gson.Gson.fromJson(Gson.java:887)
       at com.google.gson.Gson.fromJson(Gson.java:836)
       at com.google.gson.Gson.fromJson(Gson.java:808)


如果有人可以指出可能导致这种情况的原因,将会有很大的帮助。提前致谢。

最佳答案

在android SDK java lang中,禁止创建字符串use构造函数,例如new String("dd"),它鼓励使用StringFactoy

public String(String original) {
        // Android-changed: Constructor unsupported as all calls are
        //intercepted by the runtime.
        throw new UnsupportedOperationException("Use StringFactory instead.");
    }

10-07 17:08