-1

This is the source code of MainActivity. What's wrong in this?

package io.app.hasura.imad.namanyadav123.mapsactivity;

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.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // 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);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

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

This is Android manifest file, I have made a Google Maps activity and try to run it but it is showing an error in my Android Studio and the app is not running.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="io.app.hasura.imad.namanyadav123.mapsactivity">

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

    <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="@string/google_maps_key" />

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

</manifest>





Error:FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
halfer
  • 19,824
  • 17
  • 99
  • 186
Naman Yadav
  • 1
  • 1
  • 5
  • post your error logs – King of Masses Jul 21 '17 at 03:57
  • errors are resolved but my app crashes whenever I run it. So plz can u tell me the problem? – Naman Yadav Jul 21 '17 at 11:15
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jul 25 '17 at 21:48
  • Ok i will not repeat this again , but resolve this problem – Naman Yadav Jul 26 '17 at 02:02

1 Answers1

0

Seems you have com.android.dex.DexIndexOverflowException:

Try add these lines in the build.gradle:

android {

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

Hope it helps...

Rai
  • 187
  • 2
  • 15
  • this code worked well as it didn't show the error but my app crashes whenever I run it. – Naman Yadav Jul 21 '17 at 11:13
  • Do we have to pass the explicit intent to run it or the mapsactivity Will itself run it without any intent ?Plz tell – Naman Yadav Jul 21 '17 at 11:16
  • These are my logs:- 16:05:46 Executing tasks: [:app:assembleDebug] 16:33:32 Gradle build finished in 27m 36s 699ms 16:45:11 Adb connection Error:An existing connection was forcibly closed by the remote host 16:45:12 Connection attempts: 1 – Naman Yadav Jul 21 '17 at 11:23
  • have you tried this https://stackoverflow.com/questions/7411295/error-adb-connection-erroran-existing-connection-was-forcibly-closed-by-the-r – King of Masses Jul 21 '17 at 11:37
  • not yet but i will try this now , but plz check that if i have made a mistake in my android sdk location?-- C:\Users\Lenovo\AppData\Local\Android\Sdk – Naman Yadav Jul 21 '17 at 11:53
  • yes i tried the above link given by @King of masses but it didnt resolve my problem – Naman Yadav Jul 21 '17 at 15:36
  • try this link: someone replace there usb cable or update will resolve the issue. https://stackoverflow.com/questions/20142089/cant-run-app-on-my-phone-for-testing-adb-connection-erroran-existing-connecti – Rai Jul 22 '17 at 05:07