I’m attempting to implement an animated drawable with the following…
<?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/load_0000" android:duration="50" />
<item android:drawable="@drawable/load_0001" android:duration="50" />
<item android:drawable="@drawable/load_0002" android:duration="50" />
<item android:drawable="@drawable/load_0003" android:duration="50" />
<item android:drawable="@drawable/load_0004" android:duration="50" />
<item android:drawable="@drawable/load_0005" android:duration="50" />
<item android:drawable="@drawable/load_0006" android:duration="50" />
<item android:drawable="@drawable/load_0007" android:duration="50" />
<item android:drawable="@drawable/load_0008" android:duration="50" />
<item android:drawable="@drawable/load_0009" android:duration="50" />
</animation-list>
However, when I execute the following code I get thrown back a null pointer…
ImageView img = (ImageView)findViewById(R.id.load_bar);
img.setBackgroundResource(R.drawable.loader_animation); //null here.
Why? loader_animation is the files name and it is located in drawable/
The problem is that
imgis null:Is there a View in the xml you have loaded with
setContentView(or inflated and added to the contentView) that has the idload_bar?Mind you, just excisting in some XML, or loading it later does not work. findViewById finds current views!
If you have not loaded it, use an
inflater.