Reputation: 133
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;
}
}
Upvotes: 2
Views: 1587
Reputation: 2013
EDIT --- I recommend you try the Genymotion instead of the eclipse android emulator.
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.
Upvotes: 1
Reputation: 2823
Are you testing your application on Emulator or device..Because the google MapV2 requires a Android device with Google play apk installed in it.
Upvotes: 0