I am working on an app where one activity is a very complex code with different views inflated in a single layout like webview(which is using html files from sdcard with images),imageviews,scrolls.At starting this Activity I am getting these errors.
E/AndroidRuntime(600): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime(600): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime(600): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
E/AndroidRuntime(600): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
E/AndroidRuntime(600): ... 29 more
E/AndroidRuntime(600): Caused by: java.lang.OutOfMemoryError
E/AndroidRuntime(600): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(600): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
E/AndroidRuntime(600): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
E/AndroidRuntime(600): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
E/AndroidRuntime(600): at android.content.res.Resources.loadDrawable(Resources.java:1935)
E/AndroidRuntime(600): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime(600): at android.view.View.<init>(View.java:2785)
E/AndroidRuntime(600): at android.view.View.<init>(View.java:2722)
E/AndroidRuntime(600): at android.view.ViewGroup.<init>(ViewGroup.java:379)
E/AndroidRuntime(600): at android.widget.RelativeLayout.<init>(RelativeLayout.java:174)
E/AndroidRuntime(600): ... 32 more
How to solve this problem I have tried this code but still not knowing what to do?
@Override
protected void onDestroy() {
super.onDestroy();
unbindDrawables(findViewById(R.id.rootView));
System.gc();
}
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
What is the possible way to solve this problem? Please Help