iie iie - 2 months ago 11
Android Question

Unable to use Google Maps API in Android App

I have a problem with Google Maps in my Android app.

I've switched to Google's API and also changed the application's SDK in Project Properties.

This is the app's Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="menu.dot"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/icon">
<uses-library android:name="com.google.android.maps" />
<activity android:name="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>
<activity android:name=".About">
android:label="@string/about_title"
android:theme="@android:style/Theme.Dialog" >
</activity>
<activity android:name=".Exit">
andorid:label="@string/exit_title">
</activity>
<activity android:name=".Options">
</activity>
<activity android:name=".Start">
</activity>
<activity android:name=".Create">
</activity>
<activity android:name=".Where">
</activity>
<activity android:name=".Proceed">
</activity>
<activity android:name=".Finish">
</activity>
<activity android:name=".Login">
</activity>
<activity android:name=".OK">
</activity>
<activity android:name=".UserPanel">
</activity>
<activity android:name=".Managero">
</activity>
<activity android:name=".Edition">
</activity>
<activity android:name=".Done">
</activity>
<activity android:name=".Delete">
</activity>
<activity android:name=".Map">
</activity>

</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk android:minSdkVersion="3" />
</manifest>


I also have the key from Google.

map.xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- This file is /res/layout/mapview.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/zoomin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:onClick="myClickHandler"
android:padding="12px" />
<Button android:id="@+id/zoomout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:onClick="myClickHandler"
android:padding="12px" />
<Button android:id="@+id/sat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Satellite"
android:onClick="myClickHandler"
android:padding="8px" />
<Button android:id="@+id/street"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Street"
android:onClick="myClickHandler"
android:padding="8px" />
<Button android:id="@+id/traffic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Traffic"
android:onClick="myClickHandler"
android:padding="8px" />
<Button android:id="@+id/normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:onClick="myClickHandler"
android:padding="8px" />
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:apiKey="my_key" />
</LinearLayout>


and finally the error from dalvik monitor

11-01 11:44:29.794: W/dalvikvm(439): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-01 11:44:29.815: E/AndroidRuntime(439): java.lang.IllegalStateException: Could not execute method of the activity


before updating I received errors about libraries [ but it was a matter of changing sdk and avd properties ].

full error:

11-01 11:44:29.815: E/AndroidRuntime(439): FATAL EXCEPTION: main
11-01 11:44:29.815: E/AndroidRuntime(439): java.lang.IllegalStateException: Could not execute method of the activity
11-01 11:44:29.815: E/AndroidRuntime(439): at android.view.View$1.onClick(View.java:2072)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.view.View.performClick(View.java:2408)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.view.View$PerformClick.run(View.java:8816)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.os.Handler.handleCallback(Handler.java:587)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.os.Handler.dispatchMessage(Handler.java:92)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.os.Looper.loop(Looper.java:123)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-01 11:44:29.815: E/AndroidRuntime(439): at java.lang.reflect.Method.invokeNative(Native Method)
11-01 11:44:29.815: E/AndroidRuntime(439): at java.lang.reflect.Method.invoke(Method.java:521)
11-01 11:44:29.815: E/AndroidRuntime(439): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-01 11:44:29.815: E/AndroidRuntime(439): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-01 11:44:29.815: E/AndroidRuntime(439): at dalvik.system.NativeStart.main(Native Method)
11-01 11:44:29.815: E/AndroidRuntime(439): Caused by: java.lang.reflect.InvocationTargetException
11-01 11:44:29.815: E/AndroidRuntime(439): at menu.dot.UserPanel.MapCl(UserPanel.java:31)
11-01 11:44:29.815: E/AndroidRuntime(439): at java.lang.reflect.Method.invokeNative(Native Method)
11-01 11:44:29.815: E/AndroidRuntime(439): at java.lang.reflect.Method.invoke(Method.java:521)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.view.View$1.onClick(View.java:2067)
11-01 11:44:29.815: E/AndroidRuntime(439): ... 11 more
11-01 11:44:29.815: E/AndroidRuntime(439): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {menu.dot/menu.dot.MapMapa}; have you declared this activity in your AndroidManifest.xml?
11-01 11:44:29.815: E/AndroidRuntime(439): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.app.Activity.startActivityForResult(Activity.java:2817)
11-01 11:44:29.815: E/AndroidRuntime(439): at android.app.Activity.startActivity(Activity.java:2923)
11-01 11:44:29.815: E/AndroidRuntime(439): ... 15 more


userPanel.java

public class UserPanel extends Activity {
Create ct = new Create();
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.panel);
}
public void ManagerCl(View v){
startActivity(new Intent(this,Managero.class));

}
public void MapCl(View v){
startActivity(new Intent(this,MapMapa.class));

}
}


mapMapa.java

public class MapMapa extends Activity {


@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Log.d("mapa", "pierwsze starcie");
setContentView(R.layout.map);
}
}


panel.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/back"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="20dip"
android:orientation="horizontal" >
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center" >
<TextView
android:text="@string/user_title"
android:textColor="#ff000066"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="24.5sp" />
<Button
android:id="@+id/goToMap_button"
android:onClick="MapCl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Map" />
<Button
android:id="@+id/setRange_button"
android:onClick="RangeCl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set Range" />
<Button
android:id="@+id/ManageProfile_button"
android:onClick="ManagerCl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Manage Profile" />

</LinearLayout>
</LinearLayout>

Answer

I think you missed a "." in your manifest before MainActivity:

<activity android:name=".MainActivity" android:label="@string/app_name">
   <intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>