Reputation: 1709
I have followed about two tutorials from vogella and some other tutorial that looked similar...very similar but to no avail. I load the app on my nexus 7 and it just crashes "Unfortunately MyMapView has stopped working" on launch.This is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.macmozart.mymapview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.macmozart.mymapview.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.macmozart.mymapview.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBZ1Bt7rjB863Jy-B05zls6k8XZsBGQ6-4" />
</application>
</manifest>
Followed by my main layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
and finally my java class:
package com.macmozart.mymapview;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.maps.*;
public class MainActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if (map != null) {
Marker hamburg = map.addMarker(new MarkerOptions()
.position(HAMBURG).title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
}
Any idea what I'm doing wrong I really need this to work
EDIT :After exporting logcat log to txt file I just copied:
10-19 11:45:08.565: W/dalvikvm(638): Class resolved by unexpected DEX: Lcom/macmozart/mymapview/MainActivity;(0x4231c508):0x418ce000 ref [Lcom/google/android/maps/MapActivity;] Lcom/google/android/maps/MapActivity;(0x4231c508):0x40064000
10-19 11:45:08.565: W/dalvikvm(638): (Lcom/macmozart/mymapview/MainActivity; had used a different Lcom/google/android/maps/MapActivity; during pre-verification)
10-19 11:45:08.565: W/dalvikvm(638): Unable to resolve superclass of Lcom/macmozart/mymapview/MainActivity; (1310)
10-19 11:45:08.565: W/dalvikvm(638): Link of class 'Lcom/macmozart/mymapview/MainActivity;' failed
10-19 11:45:08.575: D/AndroidRuntime(638): Shutting down VM
10-19 11:45:08.575: W/dalvikvm(638): threadid=1: thread exiting with uncaught exception (group=0x41bbc700)
10-19 11:45:08.575: E/AndroidRuntime(638): FATAL EXCEPTION: main
10-19 11:45:08.575: E/AndroidRuntime(638): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
10-19 11:45:08.575: E/AndroidRuntime(638): at dalvik.system.DexFile.defineClass(Native Method)
10-19 11:45:08.575: E/AndroidRuntime(638): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:211)
10-19 11:45:08.575: E/AndroidRuntime(638): at dalvik.system.DexPathList.findClass(DexPathList.java:313)
10-19 11:45:08.575: E/AndroidRuntime(638): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:51)
10-19 11:45:08.575: E/AndroidRuntime(638): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-19 11:45:08.575: E/AndroidRuntime(638): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-19 11:45:08.575: E/AndroidRuntime(638): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-19 11:45:08.575: E/AndroidRuntime(638): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
10-19 11:45:08.575: E/AndroidRuntime(638): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-19 11:45:08.575: E/AndroidRuntime(638): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-19 11:45:08.575: E/AndroidRuntime(638): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-19 11:45:08.575: E/AndroidRuntime(638): at android.os.Handler.dispatchMessage(Handler.java:99)
10-19 11:45:08.575: E/AndroidRuntime(638): at android.os.Looper.loop(Looper.java:137)
10-19 11:45:08.575: E/AndroidRuntime(638): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-19 11:45:08.575: E/AndroidRuntime(638): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 11:45:08.575: E/AndroidRuntime(638): at java.lang.reflect.Method.invoke(Method.java:525)
10-19 11:45:08.575: E/AndroidRuntime(638): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-19 11:45:08.575: E/AndroidRuntime(638): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-19 11:45:08.575: E/AndroidRuntime(638): at dalvik.system.NativeStart.main(Native Method)
10-19 11:45:10.905: I/Process(638): Sending signal. PID: 638 SIG: 9
Upvotes: 0
Views: 3902
Reputation: 1709
Thanx for all the help I realised I hadnt selected the Google APIs as @Kalpesh Lakhani pointed out so decided to start from scratch only that this time imported the lib project from google play services in extras, then under Project > Properties > Android > IsLibrary I referenced the libproject. Got a new key from Google API console,added all the permissions needed and under my main xml defined a new fragments as
<fragment
android:id="@+id/map"
android:layout_below="@+id/text1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
,Ran the program and just the map is showing hopefully as I read on to tagging locations I wont have any errors, thank u guys though. P.S. I didnt need to add the external JAR files hopefully when i'm exporting there is a detailed explanation since google-lib project is showing as a project as well.
Reference video for this code,helps ALOT!!
Upvotes: 1
Reputation: 11
I think your code is correct.
I would remove maps.jar of the library tab of your project build path and then you have to choose Google Apis in your Android project properties .
Upvotes: 1
Reputation: 34016
Check that maps.jar is not included twice in your build path. You should only include it in the libs/
folder in your project - then it will turn up in "Android private libraries" in the Java Build Path > Libraries - delete it in the build path from all other places (including android dependencies if there)
Clean and rebuild
Upvotes: 1
Reputation: 993
The problem is that your MainActivity class is likely extending com.google.android.maps.MapActivity. For the system to be able to find this class you need to do two things:
First make sure your project is including the Android maps.jar in your build path. From Eclipse find
Project > Properties > Android
Then select one of the "Google APIs" as appropriate for you app. You can confirm that maps.jar is on your build path by checking:
Project > Properties > Java Build Path > Libraries > Expand "Google Apis"
Second browse to your manifest file and make sure you have the uses-library snippet nested within the tags as follows:
<manifest>
...
<application ...>
<uses-library android:name="com.google.android.maps" />
...
</application>
</manifest>
May the force be with you!
Upvotes: 1