【问题标题】:error occuring when running custom Google map application运行自定义 Google 地图应用程序时发生错误
【发布时间】:2016-12-10 11:52:05
【问题描述】:
im trying to dogoogle map application but when running emulator after gradle error occuring.Please tell me exact solution on that.



package com.example.admin.myapplication;
import android.location.Address;
import android.location.Geocoder;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.google.android.gms.maps.CameraUpdateFactory;
 import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.io.IOException;
import java.util.List;

public class Home extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
Button search_loc;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    search_loc = (Button)findViewById(R.id.search_button);
    search_loc.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onMapSearch(v);
        }
    });
}

public void onMapSearch(View view) {
    EditText locationSearch = (EditText) findViewById(R.id.editText);
    String location = locationSearch.getText().toString();
    List<Address> addressList = null;

    if (location != null || !location.equals("")) {
        Geocoder geocoder = new Geocoder(this);
        try {
            addressList = geocoder.getFromLocationName(location, 1);

        } catch (IOException e) {
            e.printStackTrace();
        }
        Address address = addressList.get(0);
        LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
        mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
        mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
    }
}


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    // Add a marker in Sydney and move the camera
    LatLng TutorialsPoint = new LatLng(21, 57);
    mMap.addMarker(new MarkerOptions().position(TutorialsPoint).title("Map"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(TutorialsPoint));
}

}

错误:任务 ':app:transformClassesWithDexForDebug' 执行失败。 com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_74 \bin\java.exe'' 以非零退出值 3 结束

【问题讨论】:

  • // 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。 buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' // classpath 'com.android.tools.build:gradle:2.1.0' // 注意:不要将您的应用程序依赖项放在这里;它们属于 // 在单个模块 build.gradle 文件中 } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }

标签: android google-maps


【解决方案1】:

在您的应用 build.gradle 文件中使用它。它会起作用的。

  android {
                ...
                defaultConfig {
                    ...
                    multiDexEnabled true
                }
            }

【讨论】:

  • 然后先清理你的项目并再次运行。
  • 然后先清理你的项目并再次运行。
  • 是的,先生,有时当我清理或重建项目时,它会成功运行,但有时却不能......为什么会这样?
  • 它发生的原因是一些垃圾值。所以每当你觉得你已经做了所有可能的解决方案,但它不起作用,然后清理你的项目并再次运行。:)
  • 当您使用超过 64k 的方法时,还会出现多桌面问题。
猜你喜欢
  • 2020-04-29
  • 1970-01-01
  • 1970-01-01
  • 2013-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多