为什么我收到 IllegalArgumentException: 类 xxxx 没有参数化?

huangapple go评论54阅读模式
英文:

Why am I getting IllegalArgumentException: class xxxx isn't parameterized?

问题

我将Android Studio更新到了Flamingo版本,同时也更新了Gradle和库文件。
之后,如果在Android Studio的模拟器中安装应用程序,它可以正常运行,但是如果从Play商店使用捆绑安装应用程序,则会失败。我认为如果从.apk文件安装,它也可以正常工作。

我收到了以下异常:

java.lang.IllegalArgumentException: 类 o4.b 没有参数化
英文:

I updated Android Studio to Flamingo, Gradle and libraries.
After that the app worked well if installed from in the Emulator by Android Studio, but it failed if the app was installed form Play Store using the bundle. I think it worked it worked if installed from an .apk file.

I get the exception:

java.lang.IllegalArgumentException: class o4.b isn't parameterized

答案1

得分: 2

以下是您要翻译的内容:

让我在这里写下我的解决方案,以防对其他人有所帮助。

经过多个小时的努力,发现异常发生在以下代码中:

Type type = new TypeToken<ArrayList<String>>() {}.getType();

我需要这段代码来使用 Gson.fromJson() 函数。

TypeToken 是通过以下导入的:

import com.google.common.reflect.TypeToken;

我不得不更改为:

import com.google.gson.reflect.TypeToken;

然后我遇到了另一个错误:

RuntimeException: 缺少类型参数

我通过这个答案解决了问题:https://stackoverflow.com/a/72520577/1363087

proguard-rules.pro 文件中,我添加了以下内容:

-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type

所有这些让我浪费了大量的时间。我希望我没有更新 Android Studio 或依赖项。

英文:

Let me write here my solution in case it helps somebody else.

After many hours, it turned out that the exception happen in this code:

Type type = new TypeToken&lt;ArrayList&lt;String&gt;&gt;() {}.getType();

I needed that code for using Gson.fromJson() function.

The TypeToken was imported using this:

import com.google.common.reflect.TypeToken;

and I had to changed to:

import com.google.gson.reflect.TypeToken;

Then I faced another error:

> RuntimeException: Missing type parameter

And I solved thanks to this answer: https://stackoverflow.com/a/72520577/1363087

In the proguard-rules.pro file I added this:

-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type

All this made me lose a huge amount of time. I wish I hadn't updated Android Studio or the dependencies.

huangapple
  • 本文由 发表于 2023年7月7日 01:03:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76631086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定