animation-list AnimationDrawable null 空指针 原因

来源:互联网 发布:js传值到jsp 编辑:程序博客网 时间:2024/04/30 08:43


在 res/drawable 目录下 有个voice_to_icon.xml文件

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"    android:oneshot="false">    <item        android:drawable="@drawable/chatto_voice_playing_f1"        android:duration="200" />    <item        android:drawable="@drawable/chatto_voice_playing_f2"        android:duration="200" />    <item        android:drawable="@drawable/chatto_voice_playing_f3"        android:duration="200" /></animation-list>


我是这样引用:

private void showAnimation() {// play voice, and start animationif (message.direct == EMMessage.Direct.RECEIVE) {voiceIconView.setImageResource(R.drawable.voice_from_icon);} else {voiceIconView.setImageResource(R.drawable.voice_to_icon);}voiceAnimation = (AnimationDrawable) voiceIconView.getDrawable();if (voiceAnimation != null)voiceAnimation.start();}

在执行到 voiceAnimation= (AnimationDrawable)voiceIconView.getDrawable();时候,报了一个空指针异常


原因是 :

@drawable/chatto_voice_playing_f1
被我放在了 res/drawable-land-hdpi 目录下
总结 :
phone开发resource放在 pad resource中会出现空指针异常,放资源的时候,得慎重注意这一状况
本小计完结了
 

0 0
原创粉丝点击