suraj shinde
suraj shinde

Reputation: 230

error occuring when running custom Google map application

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));
}

}

Error:Execution failed for task ':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'' finished with non-zero exit value 3

Upvotes: 0

Views: 63

Answers (1)

Rishabh Mahatha
Rishabh Mahatha

Reputation: 1271

Use this in your app build.gradle file. It will work.

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

Upvotes: 0

Related Questions