diff --git a/docs-source/src/en/config/api-exception.md b/docs-source/src/en/config/api-exception.md index 07318c60..1a3de7c0 100644 --- a/docs-source/src/en/config/api-exception.md +++ b/docs-source/src/en/config/api-exception.md @@ -1917,4 +1917,36 @@ loadSystem { **Solution** -Since the cache will store the found `Class` name in `SharedPreferences`, but the data directory does not exist in the System Framework, so please do not use this function in the System Framework. \ No newline at end of file +Since the cache will store the found `Class` name in `SharedPreferences`, but the data directory does not exist in the System Framework, so please do not use this function in the System Framework. + +###### exception + +::: danger IllegalStateException + +Target Class type cannot cast to **TYPE** + +::: + +**Abnormal** + +Wrong type declared when converting a string class name to the target `Class` using the `toClass` method. + +> The following example + +```kotlin +// Assume the target type is Activity but it was wrongly cast to WrongClass type +val clazz = "android.app.Activity".toClass() +``` + +**Solution** + +> The following example + +```kotlin +// Fill in the correct type +val clazz1 = "android.app.Activity".toClass() +// Do not fill in the generic declaration +val clazz2 = "android.app.Activity".toClass() +``` + +Please ensure that the generic type declared after the `toClass` method is the specified target `Class` type, and you do not need to fill in the generic declaration if the target type is not sure. \ No newline at end of file diff --git a/docs-source/src/zh-cn/config/api-exception.md b/docs-source/src/zh-cn/config/api-exception.md index ccbaa276..49d3e242 100644 --- a/docs-source/src/zh-cn/config/api-exception.md +++ b/docs-source/src/zh-cn/config/api-exception.md @@ -1848,4 +1848,36 @@ loadSystem { **解决方案** -由于缓存会将找到的 `Class` 名称存入 `SharedPreferences`,但是系统框架不存在 data 目录,所以请不要在系统框架中使用此功能。 \ No newline at end of file +由于缓存会将找到的 `Class` 名称存入 `SharedPreferences`,但是系统框架不存在 data 目录,所以请不要在系统框架中使用此功能。 + +###### exception + +::: danger IllegalStateException + +Target Class type cannot cast to **TYPE** + +::: + +**异常原因** + +使用 `toClass` 方法将字符串类名转换为目标 `Class` 时声明了错误的类型。 + +> 示例如下 + +```kotlin +// 假设目标类型是 Activity 但是被错误地转换为了 WrongClass 类型 +val clazz = "android.app.Activity".toClass() +``` + +**解决方案** + +> 示例如下 + +```kotlin +// <解决方案 1> 填写正确的类型 +val clazz1 = "android.app.Activity".toClass() +// <解决方案 2> 不填写泛型声明 +val clazz2 = "android.app.Activity".toClass() +``` + +请确保 `toClass` 方法后声明的泛型是指定的目标 `Class` 类型,在不确定目标类型的情况下你可以不需要填写泛型声明。 \ No newline at end of file