I am building an Android app that I want to open google maps with the click of a button. I want the app to find the current location of the user and give them directions to a predefined address. I started building the application before I realized there were special steps that you have to take to include this functionality. To add this feature to my project I followed the directions on these two sites:
https://developer.android.com/google/play-services/setup.html
https://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject
The problem is on the second site, when i added the library to my already existing project it caused all of my code that has findViewById(R.id.whatever) or setContentView(R.layout.whatever) to become errors. It is now telling me that i need to import the class R. If I do that it then gives me error messages on the names of all my xml files.
For example in my MainActivity it is telling me that i should change setContentView(R.layout.activity_main) to setContentView(R.layout.activity_list_item) and does this for all references to my xml files for the entire project.
I tried going back and removing the google play services library from the project and starting over but when I removed it the errors still persists. I also tried using the "fix project setup" option in Eclipse but it didn't fix the problem.
I'm wondering if anyone here has experienced this problem before? If so, how can I fix it? The application had no errors before I tried to include the google play services library. I am new to Android development so a lot of the information I have found has been either confusing to understand or doesn't seem to include enough details for me to figure it out. Thanks for your help!
Look at your imports, and check if you are importing the correct R.java from your application package, not from the android package.
Check also if your XMLs don't contain errors, otherwise R.java won't be generated.
In my case android-maps-library had to errors in two files (I have forgotten their names), I edited the two files removing errors my self. And finally I was able to used it quite nice.
i think you have correct yout Project build target, and this how:
right click on your project folder in the package explorer->propreties->Android
then porject build target and choose you Android target (Android x.xx)
but before that you need to remove import android.R;
Related
I am new to android. I am creating an android application, but there are many errors showing in MainActivity.java. Here is a screenshot
Another problem is that no style in showing in activity_main.xml. Here is the screenshot
Although I have added appcompact_v7 jar file like this
But it's not recognizing it in android option of project propertise
I have installed Support library in SDK manager. Please tell me how to solve this problem?
It is really hard to say what is wrong there. here are some things that you should try:
first of all, there are errors in your xml file (activity_xml). Please check if xml is properly formatted and you are using right tags. For debugging purpose, please make your acitivity_xml an empty FrameLayout and see if it works.
Include android 6.0 into your build path. Clean the project and try building again. Make sure your layouts are error free before doing that.
Your eclipse is unable to detect referenced library at given location. Please make sure referenced library is at same place and ERROR-FREE. If library has error, your project won't include it.
Please solve all problems one by one. First make an error free xml, then a Hello world Activity. Run it on device or emulator. Once done, try to solve library and import problem now.
Best Suggestion: Please migrate to Android Studio and gradle for better support and learning.
I have been working with Java for about a couple of months now and I have been stuck introducing Google API into my Maps app. I need some help with these imports.
Here is what I did: I was following the code of a Places API demo which I can link if needed. I ended up having to add some libraries. Before I did, I was getting errors from all of the imports that started with com.google.api.client...etc. Then once I added all of these libraries, I then got left with 2 errors out of my imports.
The errors are: the "com.google.api.client.googleapis.GoogleHeaders" and "com.google.api.client.http.json.JsonHttpParser". I am receiving them both as "cannot be resolved to a type". These errors are causing some more errors throughout the rest of my code. I was hoping someone can help me solve this. I know it should have something to do with my code, but I am not sure what is going on. I know I am missing something.
Also, I installed the Google Plugin to install the APIs and when I did, I added the "Google + API" and the "GoogleOAuth2" APIs and that is where I am stuck at. Please someone help.
Here is the screenshot: Full Screenshot
I haven't worked with Maps, but as I understand it Maps is now packaged with Google Play Services, which I have been working with recently.
Firstly, the installation of Google Play Services is well-documented and you should look at this (if you haven't done so already):
http://developer.android.com/google/play-services/setup.html
There are a few areas that cause difficulty, and one is the section "Set Up a Project with the Library". There are different possible approaches but I suggest you take the following steps.
Ensure that the Google Play Services lib (and any other libs) are defined as library projects (Properties ...Android.. Library ...IsLibrary) and that they have no errors (cleaning may not be sufficient - you may have to shut down Eclipse to remove the errors).
When the library projects are error free, add them to your project. The normal way of doing this is to REFERENCE them (check what the documentation says) but you do this by (Properties ...Android.. Library ...Add).
Then check out (Properties ... Java Build Path ...) - read the documentation but you need your libs in here.
Then clean your project but note that a restart of Eclipse may be necessary to remove the errors from your project.
There are other errors that can arise - another common one arises if you have different versions of the v4 support lib in your libs / project and you get a message "...this check is based on SHA1 at this time". This is well documented on Stack Overflow.
Good luck !
Well, I wanted to create a Library project from my existing sources so that it would help me re-use code for the paid app that I have in mind. When I saw the developer guide on how this was to be done, I thought it was very simple.
Just mark the project as a Library project and it should be converted to one.
But when I tried referencing one of the base classes in an application, the app force closes with the following exceptions
02-04 21:50:06.765: E/AndroidRuntime(699): java.lang.NoClassDefFoundError: in.my.package.name.R$layout
Let me give you some more info. I have referenced the Library project in the application and have also included the manifest entries with fully qualified activity names. I have a BaseActivity which has all the menu and re-usable code bits. The point where the above exception occurs is where I am trying to reference the layout file in this BaseActivity inside the library project.
setContentView(R.layout.apphome);
What is it that I am missing or doing wrongly?
PS: I am just noticing that When I right click on my application and go to the android tab, there is a red cross instead of a green tick in the place where the library project is referenced. But there are no visible errors on the console or in the code of the project.
Seems its a known issue.
Issue link here
Hope Google guys resolve this problem in their next SDK release.
So to be clear, the problem was that my libraries had custom styling capabilities and that was the problem.
Basically, I need help importing downloaded source or creating a project from sample source programs. I'm looking for step by step instructions for both if anyone can point me there or post the steps.
I'm very new to Android/Eclipse. I have the environments installed and have successfully written a very minor app that works on the emulator and my real Droid X. I cannot, however, get any of the Android samples into a project without errors. I've tried importing, creating from existing source, and etcetera and it's all a mess with errors everywhere.
I have, however, successfully created a new empty project, then brought the components into the project one at a time typing or pasting in code for every file. I'd hover over and import Android and other components as needed. The WiktionarySimple, for example, ran with only a couple of changes and several warnings that I left alone. (I had to add 'formatted="false" in the statements below...)
<string name="template_user_agent" formatted="false">"%s/%s (Linux; Android)"</string>
<string name="template_wotd_title" formatted="false">"Wiktionary:Word of the day/%s %s"</string>
But there has to be an easier way to import! I've done the intuitive and I've followed instructions that I've found, but to no avail. Can anyone give me a complete list as to how to import or create a project from existing source or from source I've downloaded from the web?
Step #1: Start a new Android project
Step #2: In the first page of the Android project wizard, choose the "Create project from existing source" radio button, then click the Browse button and find the directory containing the project
Step #3: Tweak settings to suit, then press Finish
Step #4: If needed (not sure if it is anymore), right-click over the project name, and choose Build Path > Configure Build Path from the context menu, and make sure the Android entry in the checklist is checked
Its quite possible that you are not importing these projects incorrectly and that you are simply running into common problems that occur when importing projects.
For instance your problem involving adding formatted="false" is quite common and due to a change in the strictness of aapt, which is explained in this question. It is likely that the sample project was created before the change and has not been updated since.
That error involving the formatted="false" can also cause many more errors, since any xml after that error is often not parsed and thus any resources declared after it are not known. So the error No resource found that matches the given name (at 'hint' with value '#string/search_hint') and others like it are often due to the formatted="false" error. I would suggest fixing all the % sign errors with the formatted="false" then letting it rebuild and see how many errors are left.
As for the String types not allowed (at 'layout_width' with value 'match_parent') a quick search on stackoverflow says that its caused because FILL_PARENT was replaced with MATCH_PARENT in Android 2.2. So you need to set your sdk for the project to be Android 2.2 or higher. Here is the link to that question as well.
This happened to me in importing the wiktionary sample and i found the solution.
Import the project through existing code
Right click project and choose properties
In 'Android' Tab the default choice is the minimum API. Changed it to the latest(highest API)
Click ok.
Clean and build your project and errors will be gone
(probably optional)
6. Change the target and Minimum SDK in the Android Manifest
I've downloaded the android source code for CallLog, Contacts, Dialing from here.
But now, when I try to import this package on Eclipse, imports like:
com.google,
com.android.internal.Telephony,
com.android.internal.R,
com.google.android.collect,
android.provider.ContactsContract.Intents.UI,
android.provider.ContactsContract.SearchSnippetColumns,
android.provider.ContactsContract.ProviderStatus,
android.provider.ContactsContract.ContactCounts,
android.content.IContentService,
android.provider.ContactsContract.Intents.UI
And many other imports, show errors saying it cannot be resolved.
So my question is, why it shows this errors? Why I cant implement it without this errors? I use the Google APIs, I've created the project from an existing source code, but I dont know why this happens.
If you're sure that you have set up the Android SDK correctly, you should try to 'clean' your Eclipse project.
This usually solves import related errors in Eclipse for me.
Try right clicking the solution / project in the project explorer and choose "fix" near the bottom.