Saturday, March 31, 2012

Setting up Google Maps in Android development.


First to generate the google maps we need to have googleAPI's jar .
next the main.xml file will be like this

 <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="07U1v4ybO9ld4IUYE6s1mzC867e9U9xLOm3lDDw"
        />



here ApiKey is genereted from the google maps site   http://code.google.com/android/add-ons/google-apis/mapkey.html

 Before that you need to generated the MD5 finger print .

This can be generated like this

Go to your WindowsPreference --->Android --->Build --->Copy the path from Default Debug keystore
It is looks like C:\Users\Maazeed\.android\debug.keystore .
Now in commad prompt we need to run the below following lines.
To get MD5 Finger print send the path of debug keystore.


keytool.exe -list -alias androiddebugkey -keystore "C:\Users\Maazeed\.android\debug.keystore" -storepass android -keypass android 






Now you get the MD5 Finger print  similarly like this

MD5 Finger print :
5F:52:33:3A:CF:66:F0:C5:2B:9A:6F:BE:EF:2B:A5:DF

Here we go we need copy and paste the sequence in this link
http://code.google.com/android/add-ons/google-apis/mapkey.html

Now you will generate the ApiKey .That looks like this .

Key generated :
07U1v4ybO9ld4IUYE6s1mzC867e9U9xLOm3lDDw

This is the APIkey you seen in first para of the discussion.

Now you can play what ever you want with the code.









/AndroidRuntime(673): java.lang.RuntimeException: Unable to instantiate activity/java.lang.ClassNotFoundException/oader dalvik.system.PathClass

I found this problem in android development because when we not include library files properly in manifest.xml.

java.lang.ClassNotFoundException


 java.lang.RuntimeException: Unable to instantiate activity

we need to set the library tag at proper place in the manifest file.
we can solve this problem by setting the <uses-library> under the application tag.

see the example below if we place the <uses-library> tag out of <application> then it causes error i stated above.


Example: The example works fine .

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.zen.mobile"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET" />
  
   
     <application android:icon="@drawable/myapp_1" android:name=".AppointmentApplication" android:label="@string/app_name">
         <uses-library android:name="com.google.android.maps"/>
        <activity android:name=".WelcomeScreen" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".AddCourse" android:label="@string/app_name" />
        <activity android:name=".RemoveCourse" android:label="@string/app_name" />
        <activity android:name=".ViewCourseMap" android:label="@string/app_name" />
    </application>
</manifest>


if you cause error even doing like this than make some inter change of <uses-library> at different ways.