【问题标题】:Getting Error with getMap() in GoogleMap在 GoogleMap 中使用 getMap() 出错
【发布时间】:2018-08-14 00:42:55
【问题描述】:

谁能告诉我我的代码错误有什么问题,我无法解决,我想知道你们能告诉我我的代码有什么问题吗。

这是我的 MapsActivity.java

package com.ite.googlemap;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity {

GoogleMap Map;
private static final LatLng ITE_COLLEGE_WEST = new LatLng(1.374935, 103.751998);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    try{
        if(Map==null) {
            Map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

            Map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
            Map.addMarker(new MarkerOptions().position(ITE_COLLEGE_WEST).title("ITE COLLEGE WEST"));

            Map.moveCamera(CameraUpdateFactory.newLatLngZoom(ITE_COLLEGE_WEST, 0));

            Map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);

        }

    }catch (Exception e){
        e.printStackTrace();
    }

}

}

这是我的 activity_maps.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ite.googlemap.MapsActivity"

class="com.google.android.gms.maps.MapFragment"
/>

这是我在运行应用程序后弹出 Messages Gradle Build 后发生的情况

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2400Library
:app:prepareComAndroidSupportAppcompatV72400Library
:app:prepareComAndroidSupportMediarouterV72400Library
:app:prepareComAndroidSupportPaletteV72400Library
:app:prepareComAndroidSupportSupportV42400Library
:app:prepareComAndroidSupportSupportVectorDrawable2400Library
:app:prepareComGoogleAndroidGmsPlayServices1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAds1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAdsLite1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAuth1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAuthBase1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAwareness1001Library
:app:prepareComGoogleAndroidGmsPlayServicesBase1001Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement1001Library
:app:prepareComGoogleAndroidGmsPlayServicesCast1001Library
:app:prepareComGoogleAndroidGmsPlayServicesCastFramework1001Library
:app:prepareComGoogleAndroidGmsPlayServicesClearcut1001Library
:app:prepareComGoogleAndroidGmsPlayServicesDrive1001Library
:app:prepareComGoogleAndroidGmsPlayServicesFitness1001Library
:app:prepareComGoogleAndroidGmsPlayServicesGames1001Library
:app:prepareComGoogleAndroidGmsPlayServicesGass1001Library
:app:prepareComGoogleAndroidGmsPlayServicesGcm1001Library
:app:prepareComGoogleAndroidGmsPlayServicesIdentity1001Library
:app:prepareComGoogleAndroidGmsPlayServicesIid1001Library
:app:prepareComGoogleAndroidGmsPlayServicesInstantapps1001Library
:app:prepareComGoogleAndroidGmsPlayServicesLocation1001Library
:app:prepareComGoogleAndroidGmsPlayServicesMaps1001Library
:app:prepareComGoogleAndroidGmsPlayServicesNearby1001Library
:app:prepareComGoogleAndroidGmsPlayServicesPanorama1001Library
:app:prepareComGoogleAndroidGmsPlayServicesPlaces1001Library
:app:prepareComGoogleAndroidGmsPlayServicesPlus1001Library
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet1001Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanager1001Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerApi1001Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4Impl1001Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks1001Library
:app:prepareComGoogleAndroidGmsPlayServicesVision1001Library
:app:prepareComGoogleAndroidGmsPlayServicesWallet1001Library
:app:prepareComGoogleAndroidGmsPlayServicesWearable1001Library
:app:prepareComGoogleFirebaseFirebaseAnalytics1001Library
:app:prepareComGoogleFirebaseFirebaseAnalyticsImpl1001Library
:app:prepareComGoogleFirebaseFirebaseAppindexing1001Library
:app:prepareComGoogleFirebaseFirebaseAuth1001Library
:app:prepareComGoogleFirebaseFirebaseCommon1001Library
:app:prepareComGoogleFirebaseFirebaseConfig1001Library
:app:prepareComGoogleFirebaseFirebaseCrash1001Library
:app:prepareComGoogleFirebaseFirebaseDatabase1001Library
:app:prepareComGoogleFirebaseFirebaseDatabaseConnection1001Library
:app:prepareComGoogleFirebaseFirebaseIid1001Library
:app:prepareComGoogleFirebaseFirebaseMessaging1001Library
:app:prepareComGoogleFirebaseFirebaseStorage1001Library
:app:prepareComGoogleFirebaseFirebaseStorageCommon1001Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
D:\GoogleMap\app\src\main\AndroidManifest.xml:33:5-35:23 Warning:
    Element uses-permission#android.permission.ACCESS_FINE_LOCATION at AndroidManifest.xml:33:5-35:23 duplicated with element declared at AndroidManifest.xml:10:5-79
:app:processDebugResources
:app:generateDebugSources
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:mergeDebugAndroidTestShaders
:app:compileDebugAndroidTestShaders
:app:generateDebugAndroidTestAssets
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
D:\GoogleMap\app\src\main\java\com\ite\googlemap\MapsActivity.java
Error:(23, 86) error: cannot find symbol method getMap()
:app:compileDebugJavaWithJavac FAILED
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

编译失败;有关详细信息,请参阅编译器错误输出。 信息:构建失败 信息:总时间:12.34 秒 信息:2个错误 信息:0 个警告 信息:在控制台中查看完整的输出

【问题讨论】:

  • 这有什么问题?
  • 我已经检查过了,但我没有找到任何重复的东西
  • 你为什么不发布你的 AndroidManifest.xml ?

标签: javascript java android android-studio


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ite.googlemap">

<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true">
</uses-feature>

<uses-permission
    android:name="android.permission.INTERNET">
</uses-permission>

<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission>

<uses-permission
    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES">
</uses-permission>

<uses-permission
    android:name="android.permission.ACCESS_COARSE_LOCATION">
</uses-permission>

<uses-permission
    android:name="android.permission.ACCESS_FINE_LOCATION">
</uses-permission>

<uses-permission
    android:name="android.permission.ACCESS_NETWORK_STATE">
</uses-permission>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">


    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyD-k_r65Lu-yME0H2uW3gjNqGdgHoub4e4" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version">
    </meta-data>

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

【讨论】:

  • 这是我的 AndroidManifest.xml
  • 有两次
  • 哦,我刚刚找到了,谢谢
【解决方案2】:

信息:Gradle 任务 [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug] :app:clean :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2400Library :app:prepareComAndroidSupportAppcompatV72400Library :app:prepareComAndroidSupportMediarouterV72400Library :app:prepareComAndroidSupportPaletteV72400Library :app:prepareComAndroidSupportSupportV42400Library :app:prepareComAndroidSupportSupportVectorDrawable2400Library :app:prepareComGoogleAndroidGmsPlayServices1001Library :app:prepareComGoogleAndroidGmsPlayServicesAds1001Library :app:prepareComGoogleAndroidGmsPlayServicesAdsLite1001Library :app:prepareComGoogleAndroidGmsPlayServicesAnalytics1001Library :app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl1001Library :app:prepareComGoogleAndroidGmsPlayServicesAppinvite1001Library :app:prepareComGoogleAndroidGmsPlayServicesAuth1001Library :app:prepareComGoogleAndroidGmsPlayServicesAuthBase1001Library :app:prepare ComGoogleAndroidGmsPlayServicesAwareness1001Library :app:prepareComGoogleAndroidGmsPlayServicesBase1001Library :app:prepareComGoogleAndroidGmsPlayServicesBasement1001Library :app:prepareComGoogleAndroidGmsPlayServicesCast1001Library :app:prepareComGoogleAndroidGmsPlayServicesCastFramework1001Library :app:prepareComGoogleAndroidGmsPlayServicesClearcut1001Library :app:prepareComGoogleAndroidGmsPlayServicesDrive1001Library :app:prepareComGoogleAndroidGmsPlayServicesFitness1001Library :app:prepareComGoogleAndroidGmsPlayServicesGames1001Library :app:prepareComGoogleAndroidGmsPlayServicesGass1001Library :app:prepareComGoogleAndroidGmsPlayServicesGcm1001Library :app:prepareComGoogleAndroidGmsPlayServicesIdentity1001Library :app:prepareComGoogleAndroidGmsPlayServicesIid1001Library :app:prepareComGoogleAndroidGmsPlayServicesInstantapps1001Library :app:prepareComGoogleAndroidGmsPlayServicesLocation1001Library :app:prepareComGoogleAndroidGmsPlayServicesMaps1001Library :app:prepareComGoogleAndroidGmsPlayServicesNearby1001Library :app:prepareComGoogleAndroidGmsPlayServicesPanorama1001Library :app:prepareComGoogleAndroidGmsPlayServicesPlaces1001Library :app:prepareComGoogleAndroidGmsPlayServicesPlus1001Library :app:prepareComGoogleAndroidGmsPlayServicesSafetynet1001Library :app:prepareComGoogleAndroidGmsPlayServicesTagmanager1001Library :app:prepareComGoogleAndroidGmsPlayServicesTagmanagerApi1001Library :app:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4Impl1001Library :app:prepareComGoogleAndroidGmsPlayServicesTasks1001Library :app:prepareComGoogleAndroidGmsPlayServicesVision1001Library :app:prepareComGoogleAndroidGmsPlayServicesWallet1001Library :app:prepareComGoogleAndroidGmsPlayServicesWearable1001Library :app:prepareComGoogleFirebaseFirebaseAnalytics1001Library :app:prepareComGoogleFirebaseFirebaseAnalyticsImpl1001Library :app:prepareComGoogleFirebaseFirebaseAppindexing1001Library :app:prepareComGoogleFirebaseFirebaseAuth1001Library :app:prepareComGoogleFirebaseFirebaseCommon1001Library :app:prepareComGoogleFirebaseFirebaseConfig1001Library :app:prepareComGoogleFirebaseFirebaseCrash1001Library :app:prepareComGoogleFirebaseFirebaseDatabase1001Library :app:prepareComGoogleFirebaseFirebaseDatabaseConnection1001Library :app:prepareComGoogleFirebaseFirebaseIid1001Library :app:prepare ComGoogleFirebaseFirebaseMessaging1001Library :app:prepareComGoogleFirebaseFirebaseStorage1001Library :app:prepareComGoogleFirebaseFirebaseStorageCommon1001Library :app:prepareDebugDependencies :app:compileDebugAidl :app:compileDebugRenderscript :app:generateDebugBuildConfig :app:mergeDebugShaders :app:compileDebugShaders :app:generateDebugAssets :app:mergeDebugAssets :app:generateDebugResValues 最新 :app:generateDebugResources :app:mergeDebugResources :app:processDebugManifest :app:processDebugResources :app:generateDebugSources :app:preDebugAndroidTestBuild UP-TO-DATE :app:prepareDebugAndroidTestDependencies :app:compileDebugAndroidTestAidl :app:processDebugAndroidTestManifest :app:compileDebugAndroidTestRenderscript :app:generateDebugAndroidTestBuildConfig :app:mergeDebugAndroidTestShaders :app:compileDebugAndroidTestShaders :app:generateDebugAndroidTestAssets :app:mergeDebugAndroidTestAssets :app:generateDebugAndroidTestResValues UP-TO-DATE :app:generateDebugAndroidTestResources :app:mergeDebugAndroidTestResources :app:processDebugAndroidTestResources :app:generateDebugAndroidTestSources :app:mockableAndroidJar 最新 :app:preDebugUnitTestBuild UP-TO-DATE :app:prepareDebugUnitTestDependencies :app:incrementalDebugJavaCompilationSafeguard :app:compileDebugJavaWithJavac :app:compileDebugJavaWithJavac - 不是增量的(例如输出已更改,之前没有执行等)。 F:\Mobile Apps\Lab 15\GoogleMap\app\src\main\java\com\ite\googlemap\MapsActivity.java 错误:(23, 86) 错误: 找不到符号方法 getMap() :app:compileDebugJavaWithJavac 失败 错误:任务 ':app:compileDebugJavaWithJavac' 执行失败。

编译失败;有关详细信息,请参阅编译器错误输出。 信息:构建失败 信息:总时间:2 分 39.708 秒 信息:2个错误 信息:0 个警告 信息:在控制台中查看完整的输出

【讨论】:

猜你喜欢
  • 2017-11-23
  • 2018-07-10
  • 1970-01-01
  • 1970-01-01
  • 2018-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多