title: Error inflating class android.widget.ProgressBar / Fatal Force Close Error - Android / Java
body: <p>I'm getting an error when attempting to display a progress bar and an image in my android application: </p>
  
  <pre><code>07-02 12:33:55.008: E/AndroidRuntime(1565): FATAL EXCEPTION: main
  07-02 12:33:55.008: E/AndroidRuntime(1565): Process: com.example.app, PID: 1565
  07-02 12:33:55.008: E/AndroidRuntime(1565): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.Download}: android.view.InflateException: Binary XML file line #42: Error inflating class android.widget.ProgressBar
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.os.Handler.dispatchMessage(Handler.java:102)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.os.Looper.loop(Looper.java:136)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.ActivityThread.main(ActivityThread.java:5001)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at java.lang.reflect.Method.invoke(Method.java:515)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at dalvik.system.NativeStart.main(Native Method)
  07-02 12:33:55.008: E/AndroidRuntime(1565): Caused by: android.view.InflateException: Binary XML file line #42: Error inflating class android.widget.ProgressBar
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.Activity.setContentView(Activity.java:1929)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at com.example.app.Download.onCreate(Download.java:78)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.Activity.performCreate(Activity.java:5231)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     ... 11 more
  07-02 12:33:55.008: E/AndroidRuntime(1565): Caused by: java.lang.reflect.InvocationTargetException
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at java.lang.reflect.Constructor.constructNative(Native Method)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     ... 25 more
  07-02 12:33:55.008: E/AndroidRuntime(1565): Caused by: java.lang.OutOfMemoryError
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.content.res.Resources.loadDrawable(Resources.java:2110)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.content.res.Resources.getDrawable(Resources.java:700)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.content.res.Resources.loadDrawable(Resources.java:2092)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.widget.ProgressBar.&lt;init&gt;(ProgressBar.java:294)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.widget.ProgressBar.&lt;init&gt;(ProgressBar.java:246)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     at android.widget.ProgressBar.&lt;init&gt;(ProgressBar.java:242)
  07-02 12:33:55.008: E/AndroidRuntime(1565):     ... 28 more
  </code></pre>
  
  <p>The error appears to crash at Line 78: <code>setContentView(R.layout.download);</code></p>
  
  <p>but it also references an out of memory issue which I've been able to resolve in the past by implementing the following: </p>
  
  <pre><code> @Override
          protected void onDestroy() {
          super.onDestroy();
  
          unbindDrawables(findViewById(R.id.ListView_layout));
          System.gc();
          }
  
          private void unbindDrawables(View view) {
              if (view.getBackground() != null) {
              view.getBackground().setCallback(null);
              }
              if (view instanceof ViewGroup) {
                  for (int i = 0; i &lt; ((ViewGroup) view).getChildCount(); i++) {
                  unbindDrawables(((ViewGroup) view).getChildAt(i));
                  }
              ((ViewGroup) view).removeAllViews();
              }
  </code></pre>
  
  <p>However in this instance the application is still crashing after doing so and I am unsure why.</p>
  
  <h2>Source:</h2>
  
  <p><a href="http://pastebin.com/KqwhFxYk" rel="nofollow">http://pastebin.com/KqwhFxYk</a></p>