Cannot resolve symbol ‘mapView’ on android studio

2017/5/3 11:40:08 人评论 次浏览 分类:Android Studio

After tons of tries I couldn’t found how to solve this.Android won’t resolve the symbol ‘mapView’ on:

mMapView = (MapView) v.findViewById(R.id.mapView);

What i’m trying to do is to get google maps to work on the emulator.I know this code is working on another PC, so my guess here that there’s something else.. (a system issue or google maps api problem)

here’s the code.Can anyone help? Thank you..

package com.example.matant.gpsportclient.Controllers;import android.app.Fragment;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import com.example.matant.gpsportclient.AsyncResponse;import com.example.matant.gpsportclient.R;import com.google.android.gms.maps.CameraUpdateFactory;import com.google.android.gms.maps.GoogleMap;import com.google.android.gms.maps.MapView;import com.google.android.gms.maps.MapsInitializer;import com.google.android.gms.maps.model.BitmapDescriptorFactory;import com.google.android.gms.maps.model.CameraPosition;import com.google.android.gms.maps.model.LatLng;import com.google.android.gms.maps.model.MarkerOptions;/** * Created by matant on 8/24/2015. */public class GoogleMapFragmentController extends Fragment implements AsyncResponse {MapView mMapView;private GoogleMap googleMap;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {// inflat and return the layoutView v = inflater.inflate(R.layout.fragment_google_map_fragment_controller, container,false);mMapView = (MapView) v.findViewById(R.id.mapView);mMapView.onCreate(savedInstanceState);mMapView.onResume();//display map immediatelytry {MapsInitializer.initialize(getActivity().getApplicationContext());} catch (Exception e) {e.printStackTrace();}googleMap = mMapView.getMap();// latitude and longitudedouble latitude = 17.385044;double longitude = 78.486671;// create markerMarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps");// Changing marker iconmarker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));// adding markergoogleMap.addMarker(marker);CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(17.385044, 78.486671)).zoom(12).build();googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));googleMap.getUiSettings().setZoomControlsEnabled(true);// Perform any camera updates herereturn v;}@Overridepublic void onResume() {super.onResume();mMapView.onResume();}@Overridepublic void onPause() {super.onPause();mMapView.onPause();}@Overridepublic void onDestroy() {super.onDestroy();mMapView.onDestroy();}@Overridepublic void onLowMemory() {super.onLowMemory();mMapView.onLowMemory();}@Overridepublic void handleResponse(String resStr) {}@Overridepublic void sendDataToDBController() {}@Overridepublic void preProcess() {}}

Manifest:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.matant.gpsportclient"android:versionCode="1"android:versionName="1.0" ><uses-featureandroid:glEsVersion="0x00020000"android:required="true" /><uses-sdkandroid:minSdkVersion="17"android:targetSdkVersion="17" /><permissionandroid:name="com.example.matant.gpsportclient.permission.MAPS_RECEIVE"android:protectionLevel="signature" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.MANAGE_DOCUMENTS" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="com.example.matant.gpsportclient.permission.MAPS_RECEIVE" /><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><activityandroid:name=".SplashScreen"android:label="@string/app_name" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".Controllers.ForgotPassword"android:label="@string/app_name" ></activity><activityandroid:name=".Controllers.Login"android:label="@string/title_activity_login" ></activity><activityandroid:name=".Controllers.SignUp"android:label="@string/title_activity_sign_up" ></activity><activityandroid:name=".MainScreen"android:label="@string/title_activity_main_screen" ></activity><meta-dataandroid:name="com.google.android.gms.version"android:value="@integer/google_play_services_version" /><meta-dataandroid:name="com.google.android.maps.v2.API_KEY"android:value="@string/google_maps_key" /></application></manifest>

build.gradle:

apply plugin: 'com.android.application'android {compileSdkVersion 21buildToolsVersion "23.0.0 "defaultConfig {applicationId "com.example.matant.gpsportclient"minSdkVersion 23targetSdkVersion 22versionCode 1versionName "1.0"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}productFlavors {}}dependencies {compile files('C:/Users/Adi/AndroidStudioProjects/GPSportClient/libs/additionnal.jar')compile files('C:/Users/Adi/AndroidStudioProjects/GPSportClient/libs/mail.jar')compile files('C:/Users/Adi/AndroidStudioProjects/GPSportClient/libs/activation.jar')compile fileTree(include: ['*.jar'], dir: 'libs')compile 'com.android.support:appcompat-v7:22.2.1'compile 'com.google.android.gms:play-services-maps:7.8.0'}

Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity" ><fragmentandroid:id="@+id/map"android:layout_width="match_parent"android:layout_height="match_parent"class="com.google.android.gms.maps.MapFragment" /></RelativeLayout>
分享到: 腾讯 新浪 人人网 邮件 收藏夹 复制网址 更多

上一篇:Android Studio App LinearLayout多层布局嵌套

下一篇:在 Android studio 中 配置Gradle 做到 “根据命令行提示符生成指定versionCode, versionName,指定...

相关教程


共有访客发表了评论 网友评论

验证码: 看不清楚?