本文介绍了ProGuard:ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我混淆了我的Java代码(在使用 ProGuard ClassCastException >)。

  java.lang.ClassCastException:com.google.gson.internal.StringMap无法转换为net.minecraft。 launcher.profile.Profile 
在java.lang.ClassCastException:com.google.gson.internal.StringMap无法转换为net.minecraft.launcher.profile.Profile
at net.minecraft.launcher.profile .ProfileManager.getSelectedProfile(SourceFile:117)
at net.minecraft.launcher.g.run(SourceFile:184)$ b $ at java.util.concurrent.Executors $ RunnableAdapter.call(Unknown Source)$ b $ java.util.concurrent.FutureTask.run(Unknown Source)$ b在java.util.concurrent.ThreadPoolExecutor.runWorker(未知源)
在java.util.concurrent.ThreadPoolExecutor
$ Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)

ClastCastException错误指向此(粗体代码行):

  public Profile getSelectedProfile()
{$ ((this.selectedProfile == null)||)b $ b (!this.profiles.containsKey(this.selectedProfile))){
if(this.profiles.get(Default)!= null)
{
this.selectedProfile =Default ;
}
else if(this.profiles.size()> 0)
{
this.selectedProfile =((Profile)this.profiles.values()。iterator 。)的.next())的getName();
}
else
{
this.selectedProfile =Default;
this.profiles.put(Default,new Profile(this.selectedProfile));
}
}
* Profile profile = this.profiles.get(this.selectedProfile); *
return profile;
}

全类文件(未混淆):
RawProfileList Class File(Un obfuscated) :
ProGuard version:5.2.1



个人资料声明字段:

  private final Map< String,Profile> profiles = new HashMap< String,Profile>(); 


解决方案

你的类很好看。 ClassCastException 意味着 Gson 不知道一个字段应该被序列化为 Profile



确保您的 proguard.cfg 包含所有。


I'm getting this annoying ClassCastException when I obfuscate my Java code (which works fine before I obfuscate using ProGuard).

   java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to net.minecraft.launcher.profile.Profile
        at java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to net.minecraft.launcher.profile.Profile
at net.minecraft.launcher.profile.ProfileManager.getSelectedProfile(SourceFile:117)
at net.minecraft.launcher.g.run(SourceFile:184)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

That ClastCastException error points to this bit of code, here (the bolded line being the exact line):

public Profile getSelectedProfile()
{
    if ((this.selectedProfile == null) || (!this.profiles.containsKey(this.selectedProfile))) {
        if (this.profiles.get("Default") != null)
        {
            this.selectedProfile = "Default";
        }
        else if (this.profiles.size() > 0)
        {
            this.selectedProfile = ((Profile)this.profiles.values().iterator().next()).getName();
        }
        else
        {
            this.selectedProfile = "Default";
            this.profiles.put("Default", new Profile(this.selectedProfile));
        }
    }
    *Profile profile = this.profiles.get(this.selectedProfile);*
    return profile;
}

Whole Class File (Un obfuscated) : http://pastebin.com/Jgh4x1SSRawProfileList Class File (Un obfuscated) : http://pastebin.com/vPxFpYfCProGuard version : 5.2.1

Declaration of Profiles field:

private final Map<String, Profile> profiles = new HashMap<String, Profile>();
解决方案

Your classes look fine. ClassCastException means that Gson didn't know that a field should have been serialized as Profile.

Make sure your proguard.cfg contains all of these rules.

这篇关于ProGuard:ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 04:56
查看更多