java - Android - Cannot resolve symbol "R" -
many responses on stackoverflow advised import r. did , made sure rebuild/clean path on 10 times before asking question.
here how files arranged:
we can see error lies somewhere between mainactivity
file or xml file.
here code mainactivity
file , pretty copy google's git hub account , error cannot identity "r" is.:
package com.eatwithme; /* * copyright (c) 2015 google inc. rights reserved. * * licensed under apache license, version 2.0 (the "license"); * may not use file except in compliance license. * may obtain copy of license @ * * http://www.apache.org/licenses/license-2.0 * * unless required applicable law or agreed in writing, software * distributed under license distributed on "as is" basis, * without warranties or conditions of kind, either express or implied. * see license specific language governing permissions , * limitations under license. */ import android.content.res.resources; import android.net.uri; import android.os.bundle; import android.text.html; import android.text.spanned; import android.view.view; import android.widget.adapterview; import android.widget.autocompletetextview; import android.widget.button; import android.widget.textview; import android.widget.toast; import com.eatwithme.activities.sampleactivitybase; import com.eatwithme.logger.log; import com.eatwithme.r; import com.google.android.gms.common.connectionresult; import com.google.android.gms.common.api.googleapiclient; import com.google.android.gms.common.api.pendingresult; import com.google.android.gms.common.api.resultcallback; import com.google.android.gms.location.places.place; import com.google.android.gms.location.places.placebuffer; import com.google.android.gms.location.places.places; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.latlngbounds; public class mainactivity extends sampleactivitybase implements googleapiclient.onconnectionfailedlistener, googleapiclient.connectioncallbacks { /** * googleapiclient wraps our service connection google play services , provides access * user's sign in state google's apis. */ protected googleapiclient mgoogleapiclient; private placeautocompleteadapter madapter; private autocompletetextview mautocompleteview; private textview mplacedetailstext; private static final latlngbounds bounds_greater_sydney = new latlngbounds( new latlng(-34.041458, 150.790100), new latlng(-33.682247, 151.383362)); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // set google api client if has not been initialised yet. if (mgoogleapiclient == null) { rebuildgoogleapiclient(); } setcontentview(r.layout.activity_main); // retrieve autocompletetextview display place suggestions. mautocompleteview = (autocompletetextview) findviewbyid(r.id.autocomplete_places); // register listener receives callbacks when suggestion has been selected mautocompleteview.setonitemclicklistener(mautocompleteclicklistener); // retrieve textview display details of selected place. mplacedetailstext = (textview) findviewbyid(r.id.place_details); // set adapter retrieve suggestions places geo data api cover // entire world. madapter = new placeautocompleteadapter(this, android.r.layout.simple_list_item_1, bounds_greater_sydney, null); mautocompleteview.setadapter(madapter); // set 'clear text' button clears text in autocomplete view button clearbutton = (button) findviewbyid(r.id.button_clear); clearbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mautocompleteview.settext(""); } }); } /** * listener handles selections suggestions autocompletetextview * displays place suggestions. * gets place id of selected item , issues request places geo data api * retrieve more details place. * * @see com.google.android.gms.location.places.geodataapi#getplacebyid(com.google.android.gms.common.api.googleapiclient, * string...) */ private adapterview.onitemclicklistener mautocompleteclicklistener = new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { /* retrieve place id of selected item adapter. adapter stores each place suggestion in placeautocomplete object read place id. */ final placeautocompleteadapter.placeautocomplete item = madapter.getitem(position); final string placeid = string.valueof(item.placeid); log.i(tag, "autocomplete item selected: " + item.description); /* issue request places geo data api retrieve place object additional details place. */ pendingresult<placebuffer> placeresult = places.geodataapi .getplacebyid(mgoogleapiclient, placeid); placeresult.setresultcallback(mupdateplacedetailscallback); toast.maketext(getapplicationcontext(), "clicked: " + item.description, toast.length_short).show(); log.i(tag, "called getplacebyid place details " + item.placeid); } }; /** * callback results places geo data api query shows first place result in * details view on screen. */ private resultcallback<placebuffer> mupdateplacedetailscallback = new resultcallback<placebuffer>() { @override public void onresult(placebuffer places) { if (!places.getstatus().issuccess()) { // request did not complete log.e(tag, "place query did not complete. error: " + places.getstatus().tostring()); return; } // place object buffer. final place place = places.get(0); // format details of place display , show in textview. mplacedetailstext.settext(formatplacedetails(getresources(), place.getname(), place.getid(), place.getaddress(), place.getphonenumber(), place.getwebsiteuri())); log.i(tag, "place details received: " + place.getname()); } }; private static spanned formatplacedetails(resources res, charsequence name, string id, charsequence address, charsequence phonenumber, uri websiteuri) { log.e(tag, res.getstring(r.string.place_details, name, id, address, phonenumber, websiteuri)); return html.fromhtml(res.getstring(r.string.place_details, name, id, address, phonenumber, websiteuri)); } /** * construct googleapiclient {@link places#geo_data_api} using automanage * functionality. * automatically sets api client handle activity lifecycle events. */ protected synchronized void rebuildgoogleapiclient() { // when build googleapiclient specify connected , connection failed // callbacks should returned, google apis our app uses , oauth 2.0 // scopes our app requests. mgoogleapiclient = new googleapiclient.builder(this) .enableautomanage(this, 0 /* clientid */, this) .addconnectioncallbacks(this) .addapi(places.geo_data_api) .build(); } /** * called when activity not connect google play services , auto manager * resolve error automatically. * in case api not available , notify user. * * @param connectionresult can inspected determine cause of failure */ @override public void onconnectionfailed(connectionresult connectionresult) { log.e(tag, "onconnectionfailed: connectionresult.geterrorcode() = " + connectionresult.geterrorcode()); // todo(developer): check error code , notify user of error state , resolution. toast.maketext(this, "could not connect google api client: error " + connectionresult.geterrorcode(), toast.length_short).show(); // disable api access in adapter because client not initialised correctly. madapter.setgoogleapiclient(null); } @override public void onconnected(bundle bundle) { // connected api client. pass adapter enable api access. madapter.setgoogleapiclient(mgoogleapiclient); log.i(tag, "googleapiclient connected."); } @override public void onconnectionsuspended(int i) { // connection api client has been suspended. disable api access in client. madapter.setgoogleapiclient(null); log.e(tag, "googleapiclient connection suspended."); } }
also, here my android manifest file (with key removed). please notice activity's name. did cause if remove com.eatwithme
before activity's name, gives me error.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.google.playservices.placecomplete" android:versioncode="1" android:versionname="1.0"> <uses-sdk android:minsdkversion="14" android:targetsdkversion="19"/> <!-- placepicker requires opengl es version 2 --> <uses-feature android:glesversion="0x00020000" android:required="true"/> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/> <application android:allowbackup="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:theme="@style/apptheme"> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <meta-data android:name="com.google.android.geo.api_key" android:value="anle"/> <activity android:name="com.eatwithme.mainactivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main"/> <category android:name="android.intent.category.launcher"/> </intent-filter> </activity> </application>
i have tried level best sadly, unable resolve conflict. 3 sources of error in opinion
1) have no r file
2) andoridmanifest file not right
3) main file isnt right 4) order of file isnt right
any guidance on issue?
the problem lies in xml manifest here:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" wrong --> package="com.example.google.playservices.placecomplete" android:versioncode="1" android:versionname="1.0">
it needs exact package name of project is:
package="com.eatwithme"
not google sample package name.