i am customizing an action bar, and i am using inflater and styles.
i added a menu.xml to a menu folder in project which i inflated into the onOptionsMenu,
the menu.xml contains the action bar item's.
Everything worked fine, until i renamed menu.xml to actionBar_menu.xmlusing refractor.
Now i can't even add it to the Inflater. it's not even declared in R.java
How do i solve the problem any hint or solution?
Thank you
Edit:
Thank you guys for your answers.
i did what you asked so i changed my action bar to actionb_menu.xml, but it still not working.
otherwise it's now declared in R.java, but eclipse editor doesn't recognize it
(ctrl+space), and even if i ignore this and continue typing the name of the file in the inflater it it still underlined as an error.
any solution for that??
Your original problem was: You can only use lowercase letters, numbers and underscores in your layout XML file name. As stated by #midoalageb
This is the answer to your edit.
Because your id wasn't initially in your R.java when you tried to do
R.id.....
eclipse has imported android.R; into your class file.
You need to go up to the top of your file delete this import:
import android.R;
then attempt to do:
R.id.whatever
again. When you press ctrl+space after R. ensure you select com.your.package.R and not android.R
hey hosni habeby look do like this,
open your new xml file the one you re named it and go to
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.something. app.OldJava" />
and replace the context value to your new java file the one you renamed also.. like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.something. app.MyNewActivityJava" />
in eclipse when you changed java file's name and it xml.. eclipse will not touch the values in the xml so we have to change it our selves also eclipse will add an import line may not refer to your R file.. if so remove it and type one that refers to your R file of your project not of Android or any library
You can only use lowercase letters, numbers and underscores in your layout XML file name. So rename your file to actionbar_menu.xml
Right click on Project. Refresh it first--> then clean it --> then rebuild it -->if there are necessary code changes then do it--> it should work.
also rename it in all small case chars
Try cleaning the project. If it still says R cannot be resolved then there should be something wrong with the xml file. Check your xml file for some extra characters that you mistyped or something of that kind. Your R file will not be built if even one xml file has an error!
Related
I am starting out in Xamarin to create an Android app for the first time, so I am following the most basic Xamarin Android tutorial. I get to the point where I am editing my Strings.xml file for my UI controls. I do so, and compile, and get:
C:\...\main.xml(0,0): Error: No resource found that matches the given name (at 'text' with value '#string/hello'). (AndroidHello)
I don't have a main.xml, but I do have a Main.axml, which was apparently generated with the solution. Am I expected to edit this file to match my .cs files? That doesn't seem right at all. Or should it be re-generated from the .cs somehow?
I searched around to try to understand more about .axml files, so I understand that they can be used to specify a layout, instead of doing so in C# code. So I thought I could just delete the .axml file and rely on C# only--but then my Resource.String.whatever resources that I specified in Strings.xml won't work when referenced from my C# code.
Strings.xml.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="helloButtonText">Say Hello</string>
<string name="helloLabelText">Hello Xamarin.Android</string>
</resources>
As mentioned, the .axml file references strings that no longer exist. How should I resolve that?
You probably have the following Button defined in the main.axml file:
<Button
android:id="#+id/MyButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Hello" />
Replace the #string/Hello and you should be good to go. If you changed the string.xml then "#string/helloButtonText" might be the replacement you need, or simply "Say Hello".
can anyone tell me what is the main difference between main.xml and Activity_main.xml.
I am writing a sample pgm for a simple client server communication.In the tutorial that am following it says to add the following code in main.xml which the author says is inside layout folder. but in my package explorer main.xml is shown inside the menu folder and in my layout folder, i have only activity_main and fragment_main. this is the code that has been posted in the website.
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<ListView android:id=”#+id/list”
android:layout_width=”fill_parent”
android:layout_height=”0dip”
android:layout_weight=”1″
android:transcriptMode=”alwaysScroll”
android:cacheColorHint=”#00000000″
android:listSelector=”#android:color/transparent”/>
<LinearLayout android:id=”#+id/footer”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:orientation=”horizontal”
android:gravity=”bottom”>
<EditText android:inputType=”textMultiLine|textNoSuggestions”
android:layout_width=”0dp”
android:layout_height=”40dp”
android:id=”#+id/editText”
android:layout_weight=”1″/>
<Button android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”#+id/send_button”
android:layout_gravity=”center_vertical”
android:text=”send” />
</LinearLayout>
</LinearLayout>
my question is where exactly am i supposed to use this code? in main.xml in menu folder or activity_main.xml? plz help
Put the code in the activity_main.xml file.
activity_main.xml and main.xml described in your tutorial are referring the same thing (a layout file). You can find it under 'res/layout' in the package explorer in ADT.
(Do not put the layout code in the .xml file in the menu folder)
You could actually name the .xml file anything you want as long as it is properly declared in your Java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);//<-------your xml file is declared here
I believe it is just the newer version of ADT that names the file activity_main.xml by default.
Whatever your tutorial is saying in regards to main.xml use your activity_main.xml instead.
alternatively from within ADT navigate to 'res/layout' and right click on the activity_main.xml select refactor->rename and rename the file to main.xml so everything matches your tutorial
where exactly am i supposed to use this code
This code would go inside activity_main.xml because it is a layout file.
menus
If it was a menu it would look a lot different such as having menu items instead of Views. And it would start and end with the <menu> </menu> tags. A menu file can be inflated to be used with your menu buttons whether that be a hard menu button, from the ActionBar, or inflated to be used somewhere else.
Menus
layouts
layouts will contain your Views such as ViewGroups (LinearLayout, RelativeLayout, etc..) and child Views like TextViews, Buttons, etc... The layout files can be named whatever you like (assuming they follow the naming conventions for layout file names). Then you use that name in your Activity to set the layout using setContentView(R.layout.some_layout_name)
Layouts
The code you posted is layout code; it should go into layout/activity_main.xml. The menu/main.xml file describes a menu named 'main'.
You need to add the code in layout/activity_main.xml. The tutorial main.xml corresponds to your activity_main.xml. This is the xml that is inflated in your Launcher activity (normally using setContentView(R.layout.activity_main) api in onCreate() function). This xml name can be anything. While creating the application, you get the option to give name to this xml. The default name is activity_xml.
The main.xm which is inside menu folder is used for sub menus in your applicaion. If you click the menu button inside your application, sub menu will come up. The layout of this sub menus is controlled by main.xml in menu folder.
I am trying to define a layout of my custom view with the id cannonView as the following.
<com.myapp.CannonView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cannonView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
This XML is placed under the layout folder. The problem is that the R.id.cannonView is not generating.
I found the answer myself. The problem was that I did not specify the right qualified class name at first. That was the reason ADT did not create this constant in first place.
When I corrected the problem with the right qualified class name, R.id was still not there. I even tried deleting R.java so that ADT regenerated it but that didn't help either.
I had some other compilation errors as well. When I fixed those, R.java generated itself and the id in question was there.
After adding a new Activity to my project I get following error while compiling the layout
Gradle: Error parsing XML: not well-formed (invalid token)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_password"
android:text="<password>"/>
</LinearLayout>
"http://schemas.android.com/apk/res/android" is marked red and hovering pops following message up
URI is not registered ( Setting | Project Settings | Schemas and DTDs )
My Settings>Project Settings>Schemas and DTDs look like that:
I already found some similar questions around here but nothing helped me to solve this issue. I hope someone has an idea... :)
I was having a similar issue. However, the comments did not assist me in the solution to this issue. This answer from this question actually solved my problem.
Summary:
Go to "File > Project Structure > Modules", click "add" and then click "android" and "apply/ok". That should solve anyone having a similar problem but the comments for this question are not helping you.
For me, the problem occured when I created my own subfolder for old code.
Specifically, Android Studio threw an error for all layout files that weren't in the default folder ../res/drawable/, but instead placed in my own subfolder ../res/drawable/backup.
I got the same error for a long time and none of the answers I found online really helped me, or probably I wasn't looking the right way. At the end what I found out was the way I named the directory. So, I was trying to make the landscape layout for my app and named it layout_land. That kept showing me the URI is not registered error. I just had to change the directory name to layout-land.
Summary: No underscores in directory names!
My issue was creating new resource directory for some animation work. The files were .xml and I chose file type as "xml". I got this problem. Changing the file type to "values" and the problem went away. No idea why, could someone explain this to me? I'm using Android Studio on an iMac.
GO to settings >Language&Framework >Schemas&DTD
here add Uri used in your code.
Some special characters not allowed here.
Directly to assign text then with warning
android:text="value"
#string file from get then avoid warning
android:text="#string/hello"
res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
</resources>
For me this problem was gone when I have made following changes to my project structure on Android Studio.
file->project structure ->SDK Location -> enable check mark for "Use embedded JDK (recommended).
Hope this will help someone.
First thing is go to the project folder in the Android studio and check for any folders which are created by you. It will show this error if you have created any folder on your own.
I am creating a few layouts with the root element being merge. inside the merge element i have a ScrollView containing a TextView. Here is the file:
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:id="#+id/scroll"
android:padding="6dp"
android:layout_below="#id/headingLayout"
android:layout_above="#id/tabsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/aboutTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
</merge>
I am getting 2 errors: there is no resource to match the layout_below and layout_above names i have put in.
I have another layout xml file including very similar components, some of which also reference #id/headingLayout and #id/tabsLayout. Both of these XML layout files do not contain the component with name headingLayout or tabsLayout
Why is it that one layout file has no errors about these references and the other layout file does? What the crap am i doing wrong, the app will build and run like i expect, until i add this merge to another layout?
I have even tried copying the xml from the working layout file, to find that it gives the same errors, something must be wrong with my new layout file. I have tried cleaning, rebuilding, opening/closing eclipse..
Wow, this is a strange fix i have found for this. the layout i have given in my question above(the one giving errors) is named about.xml. the layout with no errors which also includes merge and references to other xml components is named home.xml. the xml file including the referenced components is named base_layout.xml.
in the eclipse Package Explorer under the layout folder, items are listed alphabetically. so the home.xml file came after base_layout.xml, and could therefore reference the components inside it. Since about.xml came before base_layout.xml, about.xml could not reference anything inside base_layout.xml.
so i just renamed base_layout.xml to aaa_base_layout.xml so it would be first, and all errors go away.