Import R with downloaded source code - android

I've downloaded the ContactsList example from google's developer site. When creating a new project with this code, I've got several errors, and I realized that all are because the same thing: It doesn't get the R resources, so it is importing the android.R.
I've tryed celaning the project, trying to solve layout's issues if the had, etc.. but still doesn't create the R.java file in "gen".
So, I don't know what I'm forgoting to do because I tought that code downloaded directly from google should work fine.

Check for the following:
Check whether there is error in your xml file.
Check whether you are missing any jar(additional) file.
Try to change your target sdk to some other and change to original.

Related

There is no "res/layout/" folder in my android project (using eclipse, libGDX)

I want to add ads to my aplication via adMob, so I followed this tutorial: https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=de#play
It says:
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="#+id/mainLayout".
But I have no layouts! Not even a layout folder!
I tried this solution, but it did not work for me: src folder empty on creating new Android project
There was allready everything installed and uninstalling and then installing again also didn't work.
I guess it might have something to do with the gradle-project. I created the project with the gdx-setup tool. But I don't know anything about gradle.
I hope someone can help me.
You don't need to create a layout folder you can do it all programatically.
Look at our open source libgdx game for an example:
https://github.com/MapleScotDevelopment/LoggerBill

Missing file in res>layout

I'm currently using eclipse to build android apps, but according to the tutorial, there will file named main.xml in res>layout to create the design of my apps. However my layout is empty.
I had posted about the same issue with extra information, but it was deleted. However, I found a solution so you can get the layout folder populated with the blank activity.
Instead of using the ADT package, download Eclipse and the SDK separately. Follow the details here, but download and unpack the SDK first. Click the DOWNLOAD FOR OTHER PLATFORMS link.
You will also need the location of your java JRE bin folder.
I hope that helps,
Lee.
Create a new project based on a template and everything will be set up as expected. It sounds like you may be new to Android. I would suggest reading through the documentation for building your first app. It will tell you all you need to know.
https://developer.android.com/training/basics/firstapp/index.html

can't get R.anim in my project

I started some android programming and I am trying to do some animation in my activity. but all references are using interpolators and files from res/anim folder which I can't find in my project. Also, when I am using R.anim I am getting an error that it doesn't exist.
Is there any API to download?
Thank you
You need to import the R file. You should see something like below in the import list of your class file.
import <your.app.package>.R
I had the same problem, and none of the solutions above worked.
In the end, I got it to work by referencing it as android.R.anim as explained here.
Had similiar issue, but could access all other R.* locations but not anim.
Problem was with an anim xml file missing:
xmlns:android="http://schemas.android.com/apk/res/android"
Nothing in IDE detected any error. Hope this helps someone else.
No, R file is not some API. It is a file generated by the Android build system from existing resources. If you can't find some particular references to resources, this means these resources don't exist. You should put them where they belong. Read more about providing resources for your applications.
No api. Your config is wrong in some way. Attach some code, possibly a screenshot of your project browser so we can see the folder/file structure.
In my case there was yet another reason why my R.anim.shake hadn't been recognized. It was because my project is divided into 2 modules (app and library). I placed the animation file (shake.xml) in the app module while I was trying to reference it from the library module. Moving the shake.xml file to library/src/main/res/anim solved the problem.

Newly created layout files not added to R.java

I have tried literally everything to figure out why no new layout files are being added to my R.java file in eclipse. Nothing is working.
I have:
Restarted Eclipse
Used Project>Clean
Deleted R.java (had to restore because it would not autoregenerate no matter what I did)
Ensured all methods are defined in SDK version
Rebuilt the project
Unchecked auto-build
Every combination of above options
Been tempted to throw my computer across the room
Does anyone have any suggestions?
Check you don't have any errors inside one of your xml files. That is, check not only for xml file name errors but also for errors in the xml code, for example an illegal attribute, a forgotten tag etc. Check this in all your xml files, not just layout files but also anim, xml drawables etc. These errors don't show up in the error log but will prevent the R.java from being generated.
When I experienced the same issue as you this was often the reason. The error highlight was only visible inside the file, not the error log.
Net, go through every xml file with a fine comb.
I faced this kind of problem many times. From my thoughts it is caused due to the problem of images in the drawable or case sensitive of layout file (everything should be small). Check your case sensitive of layout file.
I will give all possible solutions that i had done when something like this happened with me
Project-->clean
Check for library if there was any for that
RightClick-->Properties-->Android-->add
Restart Eclipse
Check in
the manifest for if you have many packages make sure u are using the
activity declared package.
I would check the imported R. The problem could be that you have
import android.R;
instead of
import com.myproject.R;
Project -> and check Build Automatically
Is there any error in your resource files? If there is any error in your resource files the R file will not be generated.
When first of u go on Project->Clean the your application then refreshing and auto genrated R.java file for your apps.
Not to be repetitive, but did you check the Android manifest file? The error there doesn't usually pop up.
Did you check for other locale letters (maybe whitespaces too?) in the filenames? Letters that look exactly like Latin.
I think I had similar problem with the names. You can try rewriting your files' names.
Project Explorer (Right click on your project) -> Build Project
This worked for me.

R.java file not updating with UI element's id

I added some UI elements to the main.xml file in the res\layout folder and when I try to access them through the call, R.layout.my_uielement, the UI element that I created is not there. Even when I add a new xml file with UI elements, it still doesn't show up in the R.layout class. I have made checked the ids on them and they have the correct format (I think): android:id="#+id/my_button". What could be the problem? Do I need to compile the code first?
UPDATE:
I have already tried adb kill-server then adb start-server. It doesn't seem to help. I have also tried R.id.my_uielement, it doesn't register either.
This may not be the case for you, but sometimes when I use something from the android.R package (default android resources) and I use it in my class before making reference to anything from my own resource package, Eclipse adds the import android.R; statement in my imports. This will conflict with the default behavior of implicitly looking in your package's resources.
Check your import statements for import Android.R;. If it's there, remove it. And, if you're using anything from android.R, fully qualify it when you use it in code.
Clean project works fine. In Eclipse if you just change some xml components, it doesn't always generate a new R file. Cleaning does it.
Use R.id.your_ui_element, not R.layout.your_element
I faced this problem too. The R.java was neither generated nor updated.
If R.java is not generated when you create the project, run your 'empty` project. An R.java with references to resources will be automatically generated.
If R.java is not getting updated, Check for updates in Help -> Check for Updates
in Eclipse and update your SDK and ADT if required.
After 2 days I found a way to fix it...
I had saved half done project in my mail, so when R.java vanished i just replaced it with the old R.java file, this fixed a lot of errors, then made necessary changes and built the project(build it not clean)...I do not know whether clean and build performs the same job or not..but everytime i cleaned it , R.java used to go invisible...
Clean is working because it BUILD the project after cleaning. So the problem is ( at least it was in my case, because I switched off the Automatic Build a few days earlier ) that after you add an item or anything in a .xml file, the eclipse doesn't build it and can't refresh the R.java .
I've noticed that my R.java file is not always being properly updated when I add items to my strings.xml file or elsewhere. If I use a new value I added like R.string.newString the actual integer value might still be pointing to R.string.oldString or whatever (it seems to usually be the element directly above or below the new element in strings.xml but I haven't nailed down the pattern for sure yet).
You're not supposed to modify the R.java file, but it doesn't say anything about deleting it (not that I've seen, anyway). I've found that deleting R.java usually fixes my resource-related problems because Eclipse immediately regenerates the file with the integer values properly assigned.
Please note, I'm very much a beginner at Eclipse so I may not understand the consequences of deleting R.java but it seems to be working well for me so far. If what I'm doing is very bad, please let me know.
None of these worked for me!
The only way i can access an #+id/foo is by myPackage.R.id.foo.

Categories

Resources