XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.org.BatteryManager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<com.org.BatteryManager.BatteryView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textColor="#ffffffff"
/>
</LinearLayout>
Logcat
02-17 18:49:49.392: WARN/AppWidgetHostView(124): updateAppWidget couldn't find any view, using error view
02-17 18:49:49.392: WARN/AppWidgetHostView(124): android.view.InflateException: Binary XML file line #9: Error inflating class com.org.BatteryManager.BatteryView
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.widget.RemoteViews.apply(RemoteViews.java:930)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:250)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:73)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.os.Handler.dispatchMessage(Handler.java:99)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.os.Looper.loop(Looper.java:123)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at java.lang.reflect.Method.invoke(Method.java:521)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at dalvik.system.NativeStart.main(Native Method)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): Caused by: java.lang.ClassNotFoundException: com.org.BatteryManager.BatteryView in loader dalvik.system.PathClassLoader[.]
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
02-17 18:49:49.392: WARN/AppWidgetHostView(124): ... 15 more
I had the same confusing problem. To fix it your custom view should provide a constructor with two arguments: Context and AttributeSet as adviced here.
What is com.org.BatteryManager.BatteryView?
If you want to use a custom view then it is possible. The way to do it is create a custom view class in Java that extends some base view component class.
For example, I use custom Gallery components in lots of my applications. The gallery class will only move one frame left or right on a swipe which is different from the default behavior.
The way that I made my custom gallery is to extends the basic Gallery class --
package com.testing.whatever;
public class CustomGallery extends Gallery {
//CODE OVERRIDES HERE
}
Then in my XML code, the code looked similar to what you already have --
<com.testing.whatever.CustomGallery android:layout_width="fill_parent" android:layout_height="fill_parent" />
I suspect you're getting your error because you haven't coded com.org.BatteryManager.BatteryView or it's in the wrong place in your java files.
Related
This question already has answers here:
Android - SupportMapFragment with GoogleMaps API 2.0 giving IllegalArgumentException
(11 answers)
Closed 10 years ago.
I'm trying to make a simple android app and am having trouble fixing this bug.
The app has a 4 tab fixed button navigation and the error occurs when on the 4th tab and switching to another tab. Being on any other page works fine but the 4th tab is causing a fatal error every time. There is nothing on that page except a TextView element. Can anyone help me figure out what's wrong or point me in the right direction?
02-17 21:48:54.378: E/AndroidRuntime(5543): FATAL EXCEPTION: main
02-17 21:48:54.378: E/AndroidRuntime(5543): android.view.InflateException: Binary XML file line #12: Error inflating class fragment
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-17 21:48:54.378: E/AndroidRuntime(5543): at com.example.testthree.MainActivity$MapSectionFragment.onCreateView(MainActivity.java:241)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1264)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:523)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:495)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:476)
02-17 21:48:54.378: E/AndroidRuntime(5543): at com.example.testthree.MainActivity.onTabSelected(MainActivity.java:95)
02-17 21:48:54.378: E/AndroidRuntime(5543): at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:570)
02-17 21:48:54.378: E/AndroidRuntime(5543): at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:1067)
02-17 21:48:54.378: E/AndroidRuntime(5543): at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:489)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.view.View.performClick(View.java:4084)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.view.View$PerformClick.run(View.java:16966)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.os.Handler.handleCallback(Handler.java:615)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.os.Handler.dispatchMessage(Handler.java:92)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.os.Looper.loop(Looper.java:137)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-17 21:48:54.378: E/AndroidRuntime(5543): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 21:48:54.378: E/AndroidRuntime(5543): at java.lang.reflect.Method.invoke(Method.java:511)
02-17 21:48:54.378: E/AndroidRuntime(5543): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-17 21:48:54.378: E/AndroidRuntime(5543): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-17 21:48:54.378: E/AndroidRuntime(5543): at dalvik.system.NativeStart.main(Native Method)
02-17 21:48:54.378: E/AndroidRuntime(5543): Caused by: java.lang.IllegalArgumentException: Binary XML file line #12: Duplicate id 0x7f04000f, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
02-17 21:48:54.378: E/AndroidRuntime(5543): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-17 21:48:54.378: E/AndroidRuntime(5543): ... 30 more
Fixed it with the following code in my map fragment:
public void onDestroyView() {
super.onDestroyView();
FragmentManager fm = getActivity().getSupportFragmentManager();
Fragment fragment = (fm.findFragmentById(R.id.map));
FragmentTransaction ft = fm.beginTransaction();
ft.remove(fragment);
ft.commit();
}
While not an expert in tabs, I would appear to be a problem with the map/map fragment.
Are you including the map more than once across all the tabs?
I would try making sure the id of any added fragments (and map fragments) is unique.
You might also find it useful to remove any fragments that you are not using so as to lessen the chance for conflicts. This is likely to be something similar to removing the fragments that inside the tabs that aren't currently displayed. But like I said, I'm not an expert on tabs.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.falling.inairproandmark/com.falling.inairproandmark.Q9Popup}: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:219)
at android.app.Activity.setContentView(Activity.java:1647)
at com.falling.inairproandmark.Q9Popup.onCreate(Q9Popup.java:36)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.Button.<init>(Button.java:65)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 22 more
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1709)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:1885)
at android.widget.TextView.<init>(TextView.java:352)
at android.widget.Button.<init>(Button.java:69)
... 26 more
==
here's my xml layout:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:background="#drawable/q9popup" android:id="#+id/qnine"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</Button>
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="**********"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</AbsoluteLayout>
I don't understand why I keep getting this error :S
Please help.
Thanks
Android cannot allocate the memory for the Button. Pre-Honeycomb allocates the memory for a bitmap natively, outside the Dalvik VM, using malloc and has to rely on Java finalizers to free that memory again. Unless you call Bitmap.recycle that is.
See http://www.youtube.com/watch?v=_CruQY55HOk&feature=player_detailpage#t=650s for some info on allocation of Bitmaps.
So you have to figure out why external allocation is so high in your app. Maybe AdMob is the cause. Make sure to invoke AdView.destroy in your activity's onDestroy.
I am trying to set transparent panel using this tutorial in my app but whenever i use following xml to my activity it comes up with force to close
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/city_map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0DUEIIn35xtmC6Vk1JkFEF74kwkUjgb7HrUMKfA"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom"
android:paddingLeft="5px"
android:paddingTop="5px"
android:paddingRight="5px">
<com.pocketjourney.view.TransparentPanel
android:id="#+id/transparent_panel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5px"
android:paddingLeft="5px"
android:paddingBottom="5px"
android:paddingRight="5px">
<Button android:id="#+id/button_click_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!"/>
</com.pocketjourney.view.TransparentPanel>
</LinearLayout>
</FrameLayout>
Thanks
logcat
07-04 00:14:09.874: DEBUG/ddm-heap(3005): Got feature list request
07-04 00:14:09.974: DEBUG/dalvikvm(55): GC freed 315 objects / 12176 bytes in 264ms
07-04 00:14:10.004: WARN/dalvikvm(101): disableGcForExternalAlloc: false
07-04 00:14:10.084: WARN/dalvikvm(3005): Unable to resolve superclass of Lcom/droidnova/android/howto/optionmenu/ControlMenu; (69)
07-04 00:14:10.084: WARN/dalvikvm(3005): Link of class 'Lcom/droidnova/android/howto/optionmenu/ControlMenu;' failed
07-04 00:14:10.094: DEBUG/AndroidRuntime(3005): Shutting down VM
07-04 00:14:10.094: WARN/dalvikvm(3005): threadid=3: thread exiting with uncaught exception (group=0x4001e390)
07-04 00:14:10.104: ERROR/AndroidRuntime(3005): Uncaught handler: thread main exiting due to uncaught exception
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.droidnova.android.howto.optionmenu/com.droidnova.android.howto.optionmenu.ControlMenu}: java.lang.ClassNotFoundException: com.droidnova.android.howto.optionmenu.ControlMenu in loader dalvik.system.PathClassLoader#448a0d70
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2497)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.os.Looper.loop(Looper.java:123)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.app.ActivityThread.main(ActivityThread.java:4595)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at java.lang.reflect.Method.invoke(Method.java:521)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at dalvik.system.NativeStart.main(Native Method)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): Caused by: java.lang.ClassNotFoundException: com.droidnova.android.howto.optionmenu.ControlMenu in loader dalvik.system.PathClassLoader#448a0d70
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-04 00:14:10.124: ERROR/AndroidRuntime(3005): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2489)
and now i am getting this
07-04 00:28:31.914: ERROR/ActivityManager(101): fail to set top app changed!
the XML declaration
is saying in the packages com/pocketjourney/view there will a class called TransparentPanel
so I assume your package isn't that, you will have named it yourself so you need to update your XML
com.your.package.TransparentPanel
I am trying to inflate a layout containing a Fragment using the backwards compatibility package. I took the jar file and placed it in the libs folder of my project. I extended Fragment and then tried to inflate it by setting the contentView of the Activity to
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<fragment
class="com.test.fragments.AdFragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/></LinearLayout>
But when I set the content view it fails with a ClassNotFoundException for the fragment tag.
Here is the logcat output.
java.lang.RuntimeException: Unable to start activity ComponentInfo{}: \
android.view.InflateException: Binary XML file line #51: \
Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1777)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1793)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3848)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #51: \
Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:211)
at android.app.Activity.setContentView(Activity.java:1657)
at com.test.base.activities.TabbedStoreActivity.onCreate(TabbedStoreActivity.java:46)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1731)
... 11 more
Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader \
dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar: \
/data/app/com.test.test.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.view.LayoutInflater.createView(LayoutInflater.java:471)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
... 20 more
Make sure your activity is inheriting from FragmentActivity, otherwise <fragment> does not work. Here is a sample project demonstrating this.
in my onCreate(), i am simply using an xml as a content view for the activity. why am i getting a memory leak. is it something i am doing wrong?
My xml simply has 5 image buttons, with a statelistdrawable (selector) for each imagebutton. each image is just 16kb in size. (So i am using 10 images- a pressed state image and an normal state image for each button).
Nowhere in my activity am i using LayoutInflator..
Shouldn't android be recycling bimaps on its own when setting the content view from xml?
I am getting error something like this:
02-17 09:18:39.797: ERROR/AndroidRuntime(372): Uncaught handler: thread main exiting due to uncaught exception
02-17 09:18:39.817: ERROR/AndroidRuntime(372): java.lang.RuntimeException: Unable to start activity ComponentInfo{***.***.*****.activity/***.***.*****.home.HomeScreenActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class java.lang.reflect.Constructor
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.os.Handler.dispatchMessage(Handler.java:99)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.os.Looper.loop(Looper.java:123)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.app.ActivityThread.main(ActivityThread.java:4203)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at java.lang.reflect.Method.invoke(Method.java:521)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at dalvik.system.NativeStart.main(Native Method)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class java.lang.reflect.Constructor
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.app.Activity.setContentView(Activity.java:1620)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at ***.***.*****.home.HomeScreenActivity.onCreate(HomeScreenActivity.java:35)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): ... 11 more
02-17 09:18:39.817: ERROR/AndroidRuntime(372): Caused by: java.lang.reflect.InvocationTargetException
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.widget.RelativeLayout.<init>(RelativeLayout.java:171)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at java.lang.reflect.Constructor.constructNative(Native Method)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): ... 21 more
02-17 09:18:39.817: ERROR/AndroidRuntime(372): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:439)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:322)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:688)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.content.res.Resources.loadDrawable(Resources.java:1710)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.View.<init>(View.java:1846)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.View.<init>(View.java:1795)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): at android.view.ViewGroup.<init>(ViewGroup.java:282)
02-17 09:18:39.817: ERROR/AndroidRuntime(372): ... 25 more
I replaced the images, and the code worked without the application hanging up, but stikll my ddms log was going crazy with the following errors:
02-17 09:18:37.287: ERROR/(372): VM won't let us allocate 270000 bytes
02-17 09:18:37.287: ERROR/dalvikvm-heap(372): 270000-byte external allocation too large for this process.
02-17 09:18:37.287: ERROR/(372): VM won't let us allocate 270000 bytes
02-17 09:18:37.287: ERROR/dalvikvm-heap(372): 270000-byte external allocation too large for this process.
02-17 09:18:37.287: ERROR/(372): VM won't let us allocate 270000 bytes
02-17 09:18:37.287: ERROR/dalvikvm-heap(372): 270000-byte external allocation too large for this process.
02-17 09:18:37.287: ERROR/(372): VM won't let us allocate 270000 bytes
02-17 09:18:37.287: ERROR/dalvikvm-heap(372): 264600-byte external allocation too large for this process.
..
.
.
.
.
Although the app is working, i would like to know what i am doing wrong. or is it a bug in the buggy android system?
attaching the code:
public class VirtualHomeActivity extends Activity {
ImageButton imgbtn1, imgbtn2, imgbtn3, imgbtn4,
imgbtn5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
}
}
layout home.xml:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layoutAnimation="#anim/home_screen_animation_controller" android:background="#drawable/bg_application">
<ImageButton android:id="#+id/imgBtn1"
android:layout_width="340dip" android:scaleType="fitCenter" android:layout_height="100dip" android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:background="#drawable/custombutton1"></ImageButton>
<ImageButton android:layout_below="#id/imgBtn1"
android:id="#+id/imgBtn2" android:layout_width="340dip" android:scaleType="fitCenter" android:layout_height="100dip" android:layout_marginTop="5dip" android:layout_marginLeft="20dip" android:background="#drawable/custombutton2"></ImageButton>
<ImageButton android:layout_below="#id/imgBtn2 android:id="#+id/imgBtn3" android:scaleType="fitCenter" android:layout_width="340dip" android:layout_height="100dip" android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:background="#drawable/custombutton3"></ImageButton>
<ImageButton android:layout_below="#id/imgBtnS3" android:id="#+id/imgBtn4" android:scaleType="fitCenter" android:layout_height="100dip" android:layout_width="340dip" android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:background="#drawable/custombutton4"></ImageButton>
<ImageButton android:layout_below="#id/imgBtn4"
android:id="#+id/imgBtn5" android:scaleType="fitCenter"
android:layout_height="100dip" android:layout_width="340dip"
android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:background="#drawable/custombutton5"></ImageButton>
</RelativeLayout>
and the selector is:(custombutton1.xml)
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/img_clicked" />
<item android:drawable="#drawable/img_unclicked" /> </selector>
i removed all other code from the activity to check whether i was creating a memory leak. But here i am jsut setting content view as my layout file, and still my ddms says VM won't let us allocate 270000 bytes
i dont think i tried to manage any activity life cycles here.
Your memory leak may be somewhere else, perhaps in how you are managing activity lifecycle changes. Take a look at the article Avoiding Memory Leaks.