在android中使用自定义Toast时黄色突出显示

时间:2016-04-19 08:56:18

标签: android android-studio toast android-toast

我正在尝试实现自定义吐司,下面是我编写的代码并将其挂钩到onClickeListner asusual

ICollection<T>

使用的代码以黄色突出显示以下错误。它在logcat中没有显示为错误,代码工作正常。高亮部分也说'可能会产生'java.lang.NullPointerException'

IEnumerable<T>

我只是不明白导致此错误的原因,我恳请您查看一下。 提前谢谢

1 个答案:

答案 0 :(得分:1)

您可以在设置customToastButton

之前检查OnClickListener是否为空
if(customToastButton!=null){
    customToastButton.setOnClickListener(...)
...
}

会显示警告,因为如果Button不存在而您继续使用它,则会抛出NullPointerException