"No resource found" When using <include layout=""> - android

In my project I have created a global header layout global_header.xml and I use it in all of my layout XML files by using <include layout="#layout/global_header.xml">.
I have used this method before, and I am currently using it in this project. My problem is that I have a layout with the following contents:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<include layout="#layout/global_header" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/global_header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Contents of global_header.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/global_header"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_alignParentTop="true"
android:background="#FFDDDDDD" >
<ImageView
android:id="#+id/global_header_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:layout_marginTop="5sp"
android:adjustViewBounds="true"
android:src="#drawable/header" />
<View
android:layout_width="fill_parent"
android:layout_height="1sp"
android:layout_alignParentBottom="true"
android:background="#FF000000" />
</RelativeLayout>
And I am getting an error on android:layout_below="#global/header" saying that:
error: Error: No resource found that matches the given name (at 'layout_below' with value '#global/header').
I have used the include in other layouts in the project and it works without a problem, but for whatever reason, this layout file will not load the ID from the header where as all other layouts do.
The project will not build with this error even though I am sure that once running on the device it will find it not a problem, has anyone else had this problem? Is there solution/workaround?
Any and all help is greatly appreciated.

Try this, specify id for include layout and use
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<include layout="#layout/global_header" android:id="#+id/header"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>

Hope both xml (main.xml & global_header.xml) is exist in your layout folder within resources.
kindly clean the project and restart your eclipse, it works.
Note# I checked your xmls I didn't got any error.

Related

Error- No resource found that matches the given name (at 'MvxItemTemplate' with value '#layout/itemc')

I am using MvvmCross to create PCL.In my Android application,I have created a mvx.mvxListView which has ItemTemplate named itemc.axml.
The file itemc.axml is created in Layout folder but still it gives this error.
Error- No resource found that matches the given name (at 'MvxItemTemplate' with value '#layout/itemc')
Why?
My FirstView.axml file is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/constD.Droid"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="Show Constituencies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button1" />
<Mvx.MvxListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource Result"
local:MvxItemTemplate="#layout/itemc" />
</LinearLayout>
and my itemc.axml file is as follows.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text name" />
</LinearLayout>
Why it is so?
Try Renaming the file itemc.axml to Itemc.axml, see if that works
I was getting this error when naming in camelCase. renaming to lowercase fixed it.

Got Warning : this linearlayout layout or its framelayout parent is possibly useless

<TabHost
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
// --------------------------- Here I got warning -------------------------
<LinearLayout
android:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible" >
// --------------------------------------------------------------------------
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white" >
</ListView>
<LinearLayout
android:id="#+id/text_entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal" >
<EditText
android:id="#+id/txt_inputText"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:hint="#string/enter_text"
android:inputType="text" />
<Button
android:id="#+id/btn_Send"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/send" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" >
</TabWidget>
</LinearLayout>
</TabHost>
How to solve this warning ? I can't find any solution. Any help will be appreciated.
I am not sure what exactly you are trying to accomplish, but you can get rid of the warning by moving FrameLayout content to a separate file and add it back to your TabHost by using <include> tag.
A possible version could look something like this:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<include layout="#layout/tab_chat_list" />
</FrameLayout>
</LinearLayout>
</TabHost>
And tab_chat_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible" >
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white" >
</ListView>
<LinearLayout
android:id="#+id/text_entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal" >
<EditText
android:id="#+id/txt_inputText"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:hint="#string/enter_text"
android:inputType="text" />
<Button
android:id="#+id/btn_Send"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/send" />
</LinearLayout>
</LinearLayout>
</merge>
Hope this helps.
Update
I noticed that some people are suggesting to remove FrameLayout. Although, that could have solved the problem in other cases, TabHost needs TabWidget and FrameLayout to function correctly.
The warning you are getting is this one:
UselessParent
Summary: Checks whether a parent layout can be removed.
Priority: 2 / 10 Severity: Warning Category: Performance
A layout with children that has no siblings, is not a scrollview or a
root layout, and does not have a background, can be removed and have
its children moved directly into the parent for a flatter and more
efficient layout hierarchy.
It can be turned off in Lint.
Update: I missed that tabhost requires a framelayout to work. Disabling the warning or going with shoe rat's solution should still fix the problem. (ignore paragraph below)
Assuming you don't need the FrameLayout (i.e. to add stuff dynamically), you can try removing it and adjusting the LinearLayout accordingly:
<LinearLayout
ndroid:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="visible" >
Take a look at the following layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rlInner"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text" />
</RelativeLayout>
</LinearLayout>
There is nothing wrong with it and any activity using this layout will run without a problem. But eclipse will give you a warning:
This RelativeLayout layout or its LinearLayout parent is useless
As you can see, I only need one of the two container layouts above. Adding the RelativeLayout with id="rlInner" does nothing to change the layout. When eclipse finds a scenario like this, it gives you an appropriate warning to indicate the redundancy.
In your scenario, you can lose the FrameLayout altogether without disturbing the layout. And this would fix the warning.
Add an ID to the parent linear layout.
It's useless because the parent linear layout doesn't have an id. It means it would be difficult or impossible to add stuff in code outside the linear layout where you got the error.

Android: <include/> layout crashes application on landscape

I tried to use the include tag to reuse the layout code from the activity_main.xml and contact_details.xml during landscape mode. I would like to display the activity_main on the left and contact_details on the right. But the application crashes when I switch to landscape mode.
This is the coding for the activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/btnAddContact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:text="Add Contact" />
</LinearLayout>
This is the coding for contact_details.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/lvContactDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
This is the coding for my layout-land/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<include layout="#layout/activity_main"/>
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#A3A3A3"/>
<include layout="#layout/contact_details"/>
</LinearLayout>
Any tips for resolving this problem? Thanks in advance.
Thanks Adinia for the suggestion. It was because I should not call back the same Layout name, which is activity_main.xml. This is the main cause of the crash. it might be a circular reference as Adinia had stated. Thanks again. By the way, I am only allowed to accept my answer in 2 days.
In your activity_main.xml ,contact_details.xml you are using
android:layout_width="fill_parent"
instead that try using
android:layout_width="wrap_content"
If not post you logcat report

Adding android:id to xml breaks entire app

I have this XML file:
<?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">
<Button android:text="Disable Filter" android:background="#drawable/buttons" style="#style/ButtonText" android:layout_weight="25" />
<ImageView android:id="#+id/imageFilter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="75" />
<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:id="#+id/horizontal" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
As soon as I add android:id="#+id/btnFilterPreview" to the Button my app stops working. Why is that?
In Netbeans to solve the issue, Right click on the Project and and chose: Clean and Build
Clean Build your project so that all id is regenerate and application will find reference of new ids.
This is a Same code of you . Running Perfect Without any changes.
I had just Clean & Re-Build Project Nothing else .
Try it.
<Button
android:id="#+id/btnFilterPreview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="25"
android:background="#drawable/ic_action_search"
android:text="Disable Filter" />
<ImageView
android:id="#+id/imageFilter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="75" />
<LinearLayout
android:id="#+id/horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="25"
android:orientation="horizontal" >
</LinearLayout>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</HorizontalScrollView>
It may also be caused Android automatically adds android.R in its header file remove it
and then Build Project Again
Besides Clean and Build, make sure you do not have duplicate IDs.
Say you have another ImageView with the same ID, it could crash when some code like
(Button)findViewById(R.id.btnFilterPreview)
is executed.

Android 1.5-specific error

I am having trouble with with getting my application to function on android 1.5. It works fine in 1.6, 2.1, and 2.2 but whenever I attempt to run it in 1.5, I get an immediate force close with the LogCat output:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.qrohlf.activites/com.qrohlf.activites.BookmarkHistoryTabActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class
java.lang.reflect.Constructor
This strikes me as very odd, as line #2 of my layout XML is just
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Any ideas? Is there some major API change between 1.5 and 1.6 in the way layout XMLs are done that I'm missing?
(I've included the rest of my layout xml below for reference)
<?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">
<include android:id="#+id/custom_titlebar" layout="#layout/custom_titlebar" />
<ViewFlipper android:id="#+id/frame_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ListView android:id="#+id/soccerteams_listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"/>
<ListView android:id="#+id/countries_listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"/>
</ViewFlipper>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="#android:color/black"
android:padding="0px">
<Button android:id="#+id/bookmarks_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/bookmarks"
android:textColor="#android:color/primary_text_dark"
android:drawableTop="#drawable/ic_bookmark_tab"
android:background="#drawable/tab_background"
android:layout_weight="1"/>
<Button android:id="#+id/history_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/history"
android:textColor="#android:color/primary_text_dark"
android:drawableTop="#drawable/ic_history_tab"
android:background="#drawable/tab_background"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Please ensure you have al required drawables in "drawable" directory. 1.5 doesn't understand "drawable-hdpi" directory and others, it only knows "drawable".

Categories

Resources