android如果声明强制关闭
问题描述:
所以我有以下代码。当我的应用程序中没有播放声音时,下面的内容被称为应用程序崩溃。据我所知,如果没有声音播放,它应该跳过if语句...那么它为什么会崩溃?android如果声明强制关闭
public void IfSoundPlayingThenStop()
if (currentSound.isPlaying())
{
currentSound.release();
}
答
最简单可行的解决方案,如果你只是不关心,偶尔空宁可忽略它们:
if (currentSound != null && currentSound.isPlaying())
currentSound.release();
否则,做任何其他使用前做一个单独的if(currentSound == null)
检查变量,并根据需要处理事物。
确保'currentSound'不为空。另外,添加一个logcat日志。 – MByD 2011-05-25 08:15:29
我怎么说不是空?它没有显示在智能感知 – karlstackoverflow 2011-05-25 08:17:15
许多方法来做到这一点。 if(currentSound == null){Log.d(“MYAPP”,“currentSound is null”)' – MByD 2011-05-25 08:18:49