gpt4 book ai didi

android - 无法在Android Studio上解析符号'mapView'

转载 作者:行者123 更新时间:2023-12-03 18:14:43 25 4
gpt4 key购买 nike

经过无数次尝试,我找不到解决方法。
Android不会在以下位置解析符号“ mapView”:

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


我正在尝试做的是让Google Maps在模拟器上工作。
我知道这段代码可以在另一台PC上运行,所以我在这里猜测还有其他问题。(系统问题或Google Maps API问题)

这是代码。
有人可以帮忙吗?谢谢..

    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;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflat and return the layout
View 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 immediately

try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}

googleMap = mMapView.getMap();
// latitude and longitude
double latitude = 17.385044;
double longitude = 78.486671;

// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("Hello Maps");

// Changing marker icon
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));

// adding marker
googleMap.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 here
return v;
}

@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}

@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}

@Override
public void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}

@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}

@Override
public void handleResponse(String resStr) {

}

@Override
public void sendDataToDBController() {

}

@Override
public void preProcess() {

}
}


表现:

    <?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-feature
android:glEsVersion="0x00020000"
android:required="true" />

<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />

<permission
android: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" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android: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>
<activity
android:name=".Controllers.ForgotPassword"
android:label="@string/app_name" >
</activity>
<activity
android:name=".Controllers.Login"
android:label="@string/title_activity_login" >
</activity>
<activity
android:name=".Controllers.SignUp"
android:label="@string/title_activity_sign_up" >
</activity>
<activity
android:name=".MainScreen"
android:label="@string/title_activity_main_screen" >
</activity>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android: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 21
buildToolsVersion "23.0.0 "
defaultConfig {
applicationId "com.example.matant.gpsportclient"
minSdkVersion 23
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles 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'
}


布局:

<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" >

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />

</RelativeLayout>

最佳答案

更换

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




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


因为片段的ID为 map。请参阅xml

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />

关于android - 无法在Android Studio上解析符号'mapView',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32299272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com