I decided to switch from having library projects to having JARs in my libs directory. This worked fine for every library except the DragSortListView library i'm using. When i run my application i get an InflateException on the DragSortListView class that has to be inflated. I had to change the XML layout so i could use the attributes for the DragSortListView (the only change I made is to the xmlns:dslv line). It's also worth noting that i can use the DragSortListView class in java files
XML layout (library as project):
<com.mobeta.android.dslv.DragSortListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dslv="http://schemas.android.com/apk/res/com.package.myprojectpackage"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
dslv:collapsed_height="2dp"
dslv:drag_enabled="true"
dslv:drag_scroll_start="1"
dslv:float_alpha="1.0"
dslv:float_background_color="#color/Transparent"
dslv:max_drag_scroll_speed="0.5"
dslv:slide_shuffle_speed="0.3"
dslv:drag_handle_id="#+id/sabnzbd_queue_drag_handle"
dslv:track_drag_sort="false"
dslv:use_default_controller="true" />
XML layout (library as JAR):
<com.mobeta.android.dslv.DragSortListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dslv="http://schemas.android.com/apk/lib/com.mobeta.android.dslv"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
dslv:collapsed_height="2dp"
dslv:drag_enabled="true"
dslv:drag_scroll_start="1"
dslv:float_alpha="1.0"
dslv:float_background_color="#color/Transparent"
dslv:max_drag_scroll_speed="0.5"
dslv:slide_shuffle_speed="0.3"
dslv:drag_handle_id="#+id/sabnzbd_queue_drag_handle"
dslv:track_drag_sort="false"
dslv:use_default_controller="true" />
InflateException (Library as JAR):
07-06 15:25:33.376: E/AndroidRuntime(22907): FATAL EXCEPTION: main
07-06 15:25:33.376: E/AndroidRuntime(22907): android.view.InflateException: Binary XML file line #32: Error inflating class com.mobeta.android.dslv.DragSortListView
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
If anyone can explain why the class can't be found in XML files and possibly give a solution on how to fix that it would be greatly appreciated!
any Android project that has resources and uses the resource reference system cannot be packaged as a jar. It has to be an Android Library for the R.java file to be generated correctly and the resources to be resolved. i.e. #color/Transparent
Reference:
http://developer.android.com/tools/projects/index.html#considerations
Related
I have a activity with a Background Image - now I would like to Change it and copied the new one in the drawable-hdmi Folder - rename it to Background an have deleted the old one in the Folder
but now I can put None Picture as Background - every time appears above mentioned error
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/background"
>
What can I do - have cleaned it already
02-11 21:58:33.653 10226-10226/de.tetzisoft.virjouthrger E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.tetzisoft.virjouthrger/de.tetzisoft.virjouthrger.ICit_A}: android.view.InflateException: Binary XML file line #1: Error inflating class
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at de.tetzisoft.virjouthrger.ICit_A.onCreate(ICit_A.java:16)
So say Android Studio
1) Make sure you name your resource "background" and not "Background". It's case-sensitive.
2) If you changed the resource using Windows Explorer and not Android Studio, refresh the project to update the resources.
3) You spelled your drawable folder like this "drawable-hdmi". It should be "drawable-hdpi".
4) Put the resource in "drawable" (default folder) just in case your device's density is mdpi or lower.
Have you tried naming it something else? Also even though you refer to it as background, have you made sure it keeps its .png extension?
Try cleaning and rebuilding your project,invalidate caches and restart.
Finally, open the folder for your app in finder and assure that background.png is in there.
I am experiencing this problem in my app and I can't seem to understand how it happen. It only occurs in Samsung Galaxy Y phone, I tried this code in other devices and it is ok.
java.lang.RuntimeException: Unable to start activity ComponentInfo{jpac.remaster.gtc/jpac.remaster.gtc.GTCSplash}: java.lang.RuntimeException: Binary XML file line #7: You must supply a layout_width attribute.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3735)
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:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Binary XML file line #7: You must supply a layout_width attribute.
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:3598)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3678)
at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1169)
at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:998)
at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:74)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:625)
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:207)
at android.app.Activity.setContentView(Activity.java:1657)
at jpac.remaster.gtc.GTCSplash.onCreate(GTCSplash.java:33)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
... 11 more
Can anyone help me with this? btw, here is the xml in question:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/tuna" >
<ImageView
android:id="#+id/dev_logo"
android:layout_width="#dimen/speech_height"
android:layout_height="#dimen/badge_height"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#string/empty"
android:scaleType="centerInside"
android:src="#drawable/logo_dark" />
</RelativeLayout>
Also the activity for this xml file is the main entry point of the app.
Thanks in advance.
If you have dimensions (or any other values or resources) specified for particular densities or screen sizes, make sure you also have them defined in the generic directory (i.e. "values", "drawable")
I got the following error:
02-13 12:37:05.015: E/AndroidRuntime(8766): FATAL EXCEPTION: main
02-13 12:37:05.015: E/AndroidRuntime(8766): android.view.InflateException: Binary XML file line #9: Error inflating class fragment
02-13 12:37:05.015: E/AndroidRuntime(8766): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
...
02-13 12:37:05.015: E/AndroidRuntime(8766): Caused by: java.lang.IllegalArgumentException: Binary XML file line #9: Duplicate id 0x7f05005f, tag null, or parent id 0x0 with another fragment for com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment
02-13 12:37:05.015: E/AndroidRuntime(8766): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
02-13 12:37:05.015: E/AndroidRuntime(8766): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-13 12:37:05.015: E/AndroidRuntime(8766): ... 27 more
I'm creating an android app with an actionbar sherlock with an horizontal swipe between the tabs. For each tab I have loaded a fragment and I have a problem in one of these.
In this fragment I have a nested fragment, which is essential for the pull-to-refresh list.
Hence, I have the following layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_people_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="#+id/frag_ptr_list"
android:name="com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fastScrollEnabled="true"
android:drawSelectorOnTop="false"
android:divider="#android:color/transparent"
android:layout_margin="10dp" />
<TextView
android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="#string/footer_loading_data" />
</LinearLayout>
And the following snippet of code:
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
activity = getActivity();
mPullRefreshListFragment = (PullToRefreshListFragment)
activity.getSupportFragmentManager().findFragmentById(R.id.frag_ptr_list);
....
}
The issue comes out when I'm swiping between the tabs, and when the fragment is redrawn.
Just to let you know, I'm using the Support Library v4.
fragments cannot hold other fragments.
but .....
With current versions of the Android Support package -- or native fragments on API Level 17 and higher -- you can nest fragments, by means of getChildFragmentManager(). Note that this means that you need to use the Android Support package version of fragments on API Levels 11-16, because even though there is a native version of fragments on those devices, that version does not have getChildFragmentManager().
Ok, that's weird.
I've received this error for one of my activities, the weird thing is that the bitmap is used in every Activity! I don't even know how to reproduce the exception, it's working fine for me (and others I think).
This is the whole stacktrace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{it.enrichman.bolloauto/it.enrichman.bolloauto.activities.ArchivioActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class android.widget.ListView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4385)
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:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class android.widget.ListView
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
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:250)
at android.app.Activity.setContentView(Activity.java:1742)
at it.enrichman.bolloauto.activities.ArchivioActivity.onCreate(ArchivioActivity.java:36)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 22 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/backrepeat.xml from color state list resource ID #0x7f020075
at android.content.res.Resources.loadColorStateList(Resources.java:1855)
at android.content.res.TypedArray.getColor(TypedArray.java:319)
at android.widget.AbsListView.<init>(AbsListView.java:632)
at android.widget.ListView.<init>(ListView.java:164)
at android.widget.ListView.<init>(ListView.java:160)
... 25 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag bitmap
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:146)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:1852)
... 29 more
The "missing" resource is this one (inside drawable folder):
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bg"
android:tileMode="repeat" />
The "bg" drawable is inside drawable-hdpi (could be that a problem?), but as I said it's used in every activity as background!
The error is called during the setting of the layout:
setContentView(R.layout.archivio);
The xml layout is this one:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLABLABLA"
android:id="#+id/archivioTextView" android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" android:textIsSelectable="false" android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" android:layout_marginRight="30dp" android:layout_marginLeft="30dp"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/listaVeicoli" android:layout_gravity="center" android:drawSelectorOnTop="false"/>
</LinearLayout>
(Some of the useless statements are put by the Designer of IntelliJ!)
I've looked for similar problems but I don't have "strange" id like #+id/list or other problems that other users encuntered..
Any help on this? What am I missing?
Thanks
In the end I've found FINALLY the solution.
I've tried with different emulator and I was having this crash only with API 10 (2.3.3) or less. Looking around the xmls and trying to do different stuff (also copying the bg drawable everywhere, or changing id to my list) I've found this weird stuff in my custom theme:
<item name="android:windowBackground">#drawable/backrepeat</item>
<item name="android:colorBackground">#drawable/backrepeat</item>
This seems to be not a problem for newer android version but for older one yes.
Just remove the colorBackground definition (that maybe should be only a color) and that's it!
I hope this will help someone else!
Create a drawable folder inside res folder.
Try keeping your bg inside "res/drawable/".
Hope this will help you.
Put your selector into the res/drawable folder and also give the Listview id as android:id="#+android:id/list".
I hope it will help you out.
Thanks.
I try to use fragments with AndroidAnnotations and maven.
It worked with Android 4.0+ , but then I tried to make it work with Android 2.3.3 and I had to use the support-v4 maven library:
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
My fragment is defined as:
<android.support.v4.app.Fragment android:id="#+id/myFragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
class="com.bla.HeaderFragment_"/>
and My Activity extends FragmentActivity
I get this exception when I run the app:
.....
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v4.app.Fragment
at android.view.LayoutInflater.createView(LayoutInflater.java:508)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
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:207)
at android.app.Activity.setContentView(Activity.java:1657)
at com.tagonsoft.codecamp.MainActivity_.setContentView(MainActivity_.java:46)
at com.tagonsoft.codecamp.MainActivity_.onCreate(MainActivity_.java:31)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more
Caused by: java.lang.NoSuchMethodException: Fragment(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)
... 22 more
Any idea why?
Try <fragment> tag and name attribute for class name. Also, you've used class name as com.bla.HeaderFragment_ , seems like a typo.
<fragment android:id="#+id/myFragment"
android:name="com.bla.HeaderFragment_"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
More Examples here.