鉴于此代码:
public class SoundAndFilterCollection {
private final Sound[] sounds;
private final Filter[] filters;
public SoundAndFilterCollection(Sound[] sounds, Filter[] filters) {
this.sounds = sounds.clone();
this.filters = filters.clone();
Arrays.sort(sounds);
Arrays.sort(filters);
}
public Sound[] getSounds() {
return sounds.clone();
}
public Filter[] getFilters() {
return filters.clone();
}
}
我在执行getSounds()时遇到NullPointerException:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object gab[].clone()' on a null object reference
at com.mycompany.messenger.push2talk.domain.SoundAndFilterCollection.getSounds(SoundAndFilterCollection.java:24)
at com.mycompany.messenger.shareinchat.chatbar.hiddenpanel.views.soundstickers.presenter.SoundStickersPanelPresenter.setSoundsViews(SoundStickersPanelPresenter.java:92)
at com.mycompany.messenger.shareinchat.chatbar.hiddenpanel.views.soundstickers.presenter.SoundStickersPanelPresenter.access$000(SoundStickersPanelPresenter.java:20)
at com.mycompany.messenger.shareinchat.chatbar.hiddenpanel.views.soundstickers.presenter.SoundStickersPanelPresenter.access$200(SoundStickersPanelPresenter.java:20)
at com.mycompany.messenger.shareinchat.chatbar.hiddenpanel.views.soundstickers.presenter.SoundStickersPanelPresenter$3.onDoneWithContext(SoundStickersPanelPresenter.java:59)
at com.mycompany.messenger.shareinchat.chatbar.hiddenpanel.views.soundstickers.presenter.SoundStickersPanelPresenter$3.onDoneWithContext(SoundStickersPanelPresenter.java:56)
at com.mycompany.deferred.Done$UIContextual.onDone(Done.java:35)
我的问题是:如何在getSounds()中使用此实现获得null对象?我已经在JDK 1.8和几个Android设备中测试了Array clone(),它永远不会返回null。
关于2 Arrays.sort()我知道他们正在排序错误的引用,我不认为它们与此崩溃相关,但我想分享代码就像它一样。< / p> PS:此外,我在各种各样的手机中遇到这种情况,所以我认为这与修改后的手机中克隆()的奇怪实现无关。
答案 0 :(得分:0)
神秘解决了,这个类正在缓存中用Gson实例化,因为我已经看到here即使没有空的构造函数也是如此。
这个类用proguard进行了混淆,所以它无法恢复序列化的信息并且用空值初始化