有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java找不到符号方法getMapAsync()

我正在尝试创建包含谷歌地图的应用程序,但我被这个错误卡住了

error: cannot find symbol method getMapAsync(SubActivity)

我尝试过类似this的东西,但没用。 当我运行应用程序时,它总是得到那个错误。有人能帮忙吗,我是安卓 studio编程新手。 这是我的一些代码

构建。格拉德尔

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':google-play-services_lib')
    compile 'com.google.安卓.gms:play-services:10.2.1'
    compile 'com.google.安卓.gms:play-services-maps:8.3.0'
    compile 'com.google.安卓.gms:play-services-location:8.3.0'
}

AndroidManifest。xml

<uses-permission 安卓:name="安卓.permission.ACCESS_COARSE_LOCATION" />
<uses-permission 安卓:name="安卓.permission.ACCESS_FINE_LOCATION" />
<uses-permission 安卓:name="安卓.permission.INTERNET" />
<meta-data
     安卓:name="com.google.安卓.geo.API_KEY"
     安卓:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxx" />

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

活动\u sub.xml

<fragment xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
            xmlns:tools="http://schemas.安卓.com/tools"
            安卓:id="@+id/map"
            安卓:name="com.google.安卓.gms.maps.SupportMapFragment"
            安卓:layout_width="match_parent"
            安卓:layout_height="match_parent"
            tools:context=".MapsActivity" />

亚活性。java

public class SubActivity extends AppCompatActivity
        implements OnItemSelectedListener, OnClickListener, OnMapReadyCallback {
        private GoogleMap gMap;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            .
            .
            .
            SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
            mapFragment.getMapAsync(this);
        }

        @Override
        public void onMapReady(GoogleMap googleMap) {
            if (ActivityCompat.checkSelfPermission(this, 安卓.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 安卓.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            googleMap.setMyLocationEnabled(true);
            googleMap.setPadding(0, 0, 0, 90);

            gMap = googleMap;

            // Add a marker in Sydney, Australia, and move the camera.
            LatLng sydney = new LatLng(-34, 151);
            gMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
            gMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
        }
}

共 (0) 个答案