I am beginner in android so some beginer problems is occured. I create second activiy and second layout xml file named getNearest.xml. The code section to show this file is
setContentView(R.layout.getNearest)
But eclipse cannot be find getNearest. It only shows .main. So what is the problem with this?
You need to build at least once to have the R.layout values updated when you create a new layout. Also make sure you saved the layout file and that it exists under the res\layout folder.
Related
I've created a duplicate file of my activity_main.xml. Why? Because I was trying to solve a problem regarding the minimum API required. So there's that red bulb notification in android studio, I clicked that, and applied the possible fix. What it did was it created that second xml file. Now, it's no use since I solved the problem in another why. This time, I'm editing the original xml file. However, when I run the program, it will display the layout of the duplicate xml file. What should I do?
There are two ways to resolve your problem,
if your are using the activity_main.xml file for your layout then delete your duplicate file activity_main.xml. Go to your MainActivity.java file and
under onCreate() method put this line setContentView(R.layout.activity_main);
this will link it to your activity_main.xml file in which your layout is defined.
if your trying to resolve the minimum API problem then right click on your Project-> Properties->Android, under Project Build Target choose a lower API then Apply and Ok to save the changes.
In your MainActivity.java file there's a line that says:
setContentView(R.layout.activity_main);
you can set any other xml file (with any name) there as a layout. Change it to the new layout's name.
I am a beginner in android and I am learning it by watching tutorials on YouTube. I completed all the initial steps for building up an android project but I am unable to find out any main.xml file or activity_main.xml file under res/layout folder. In fact, the layout folder is not even showing any drop down menu. I googled my doubts but I am unable to find any satisfactory answer. Can someone please tell me what exactly went wrong ?
Add your own activity_main.xml file to the layout folder. Right click layout -> New -> Android XML File -> Name the file activity_main and click Finish.
At least if you have the MainActivy.class file, (the launcher activity), the ide, wheater android studio or eclipse should show you if the you layout activity exist by underlining the parameters for the 'setcontentlayout()' function if it doesnt exist. The 'setoptionsmenu()' function also do the same. if they are there, your MainActivity.class should be free from errors otherwise create them and insert them.
I have started a new Android empty project.
Where can i find the graphical layout switch button ?
I have Eclipse Java EE and didn't installed any ADT plug-ins
because i am guessing they are already installed.
Do i need to put initial code before i'll be able to use it?
i read that i need to open the XML file to use the graphical layout,
the only xml file that i found is the manifest.
and accessing this file didn't get any result.
thanks,
Rami
You will find the layout xml files in /res/layout/*.xml.
These are the files that when opened will have a graphical editor.
If there aren't any then you can make one by using the new XML wizard.
Hopefully, this is a newbie question with a quick answer...
I am attempting to add a simple preferences file in a new Android project (New -> Android XML File), but it doesn't appear to be working correctly.
There is no root element to choose from when I select the Preference type layout. If I press Finish, it doesn't do anything. See screenshot below.
Thanks,
wTs
Just create a normal xml file to the project /res/xml/ folder and add your content to the file as usual. Should work just great. Eclipse detects it as a preference file once you have added the preference-xml and saved it.
You don't need to have a root element in the selection screen. Just replace whatever eclipse generates with what you want.
try refreshing the folder that the file is supposed to be in (in your example res/xml).
When I make a new android project and I go to res/values/string.xml I get a screen to add android resources instead of a XML document. I keeps getting the error about : java.lang.NullPointerException.
Is there a way to just alter a XML file (like suggested in tutorials)?
You have a small tab bar on the bottom in eclipse, where you can switch between the GUI and the plain XML file (only visible if you have already opened the file)
do you create a new xml with java or the Android xml file ? because with java it's not gonna work .