简体   繁体   中英

Android Maps V2 App constantly crashes

I have a problem with my app that uses the android api v2 in that it won't start it only keeps saying that "Unfortunately, app_name has stopped working.", I have followed every step in the guide released by google and I have also looked up similar problems here in StackOverflow and tried there solution but none seems to work unfortunately.

One of the biggest problem I seem to have is this

 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment"

even though I have added the Google Play services library and have added it to the app project. so where does the problem lie?

import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.GoogleMap;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

SupportMapFragment mMap;
GoogleMap googleMap;

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

    mMap = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);

            googleMap = mMap.getMap();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

EDIT --- I recommend you try the Genymotion instead of the eclipse android emulator.

But you can try the steps below.

You can do this steps if you alred have your API KEY

Step 1:

configuration AndroindManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.br.activitys"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="16" />

    <permission
        android:name="com.br.activitys.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.br.activitys.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />    

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
         android:debuggable="true">

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR API KEY" />

        <activity> ... </activity>

    </application>

</manifest>

Step 2: Create an emulator 4.2.2 API 17

在此处输入图片说明

After that, start and wait this completely loaded. Step 3: Download the files https://www.dropbox.com/s/m8p5jsvg9i4l5j3/com.android.vending-20130716.apk e https://www.dropbox.com/s/a90mjl9nhk4qv45/com.google.android.gms-20130716.apk Install it with ADB On windows exceute type CMD

在此处输入图片说明

The prompt will opne and you need to access your android instalation folder, in my case C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools

在此处输入图片说明

So, you will type ADB INSTALL and the path of the files you downloaded. 在此处输入图片说明

and

在此处输入图片说明

This process take some time(2 or 3 minutes), dont worry.

After that,you need restart the emulator.

step 4: Download https://www.dropbox.com/s/42bz5imaq4uty4j/google_play_services_9.7z extract the folder google_play_services insde of folder extra/google non your SDK directory (in my case C:\\Program Files (x86)\\Android\\android-sdk\\extras\\google), if the folder alredy exist, delete and replace with this new one. Now, copy the same folder google-play-services_lib which is in google_play_services\\libproject to your workspace, and import like an eclipse project. File -> Import

在此处输入图片说明

Select Android -> Existing Android Code Into Workspace

在此处输入图片说明

Select the folder you copied

在此处输入图片说明

and Finish.

Step 5: Now add the library to your project. Right Click in your project and go to properties. In android, scroll down until library and click add.

在此处输入图片说明

Choose the project you imported, and click ok

在此处输入图片说明

在此处输入图片说明

Just for sure, go Project -> Clean and select Clean All Projects

在此处输入图片说明

It's done, now just run your app.

在此处输入图片说明

您是否正在模拟器或设备上测试您的应用程序。因为Google MapV2需要安装了Google Play APK的Android设备。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM