我是 Google Maps API 的新手,我正在尝试在我的应用程序中显示地图。每次尝试都失败了,我不明白为什么。
这里是logcat。
<!-- language: c# --> 04-02 02:03:21.259: W/dalvikvm(24325): VFY: unable to resolve virtual method 3693: Lcom/kurtis/myapp/Mapexample;.getFragmentManager ()Landroid/app/FragmentManager;
04-02 02:03:21.269: W/dalvikvm(24325): VFY: unable to resolve virtual method 3693: Lcom/kurtis/myapp/Mapexample;.getFragmentManager ()Landroid/app/FragmentManager;
04-02 02:03:21.279: W/dalvikvm(24325): VFY: unable to resolve instance field 23
04-02 02:03:21.419: W/dalvikvm(24325): Unable to resolve superclass of Lmaps/p/s; (425)
04-02 02:03:21.429: W/dalvikvm(24325): Link of class 'Lmaps/p/s;' failed
04-02 02:03:21.429: W/dalvikvm(24325): Unable to resolve superclass of Lmaps/y/bo; (3818)
04-02 02:03:21.429: W/dalvikvm(24325): Link of class 'Lmaps/y/bo;' failed
04-02 02:03:21.429: W/dalvikvm(24325): Unable to resolve superclass of Lmaps/i/k; (4206)
04-02 02:03:21.429: W/dalvikvm(24325): Link of class 'Lmaps/i/k;' failed
04-02 02:03:21.429: E/dalvikvm(24325): Could not find class 'maps.i.k', referenced from method maps.z.ag.a
04-02 02:03:21.429: W/dalvikvm(24325): VFY: unable to resolve new-instance 3538 (Lmaps/i/k;) in Lmaps/z/ag;
04-02 02:03:21.979: W/dalvikvm(24325): threadid=1: thread exiting with uncaught exception (group=0x40174560)
04-02 02:03:21.979: E/AndroidRuntime(24325): FATAL EXCEPTION: main
04-02 02:03:21.979: E/AndroidRuntime(24325): java.lang.NoSuchMethodError: com.kurtis.myapp.Mapexample.getFragmentManager
04-02 02:03:21.979: E/AndroidRuntime(24325): at com.kurtis.myapp.Mapexample.onCreate(Mapexample.java:26)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.os.Looper.loop(Looper.java:130)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread.main(ActivityThread.java:3768)
04-02 02:03:21.979: E/AndroidRuntime(24325): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 02:03:21.979: E/AndroidRuntime(24325): at java.lang.reflect.Method.invoke(Method.java:507)
04-02 02:03:21.979: E/AndroidRuntime(24325): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
04-02 02:03:21.979: E/AndroidRuntime(24325): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
04-02 02:03:21.979: E/AndroidRuntime(24325): at dalvik.system.NativeStart.main(Native Method)
显现:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"
android:required="false"/>
<uses-feature android:name="android.hardware.camera.any"
android:required="false" />
<permission android:name="com.kurtis.myapp.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.kurtis.myapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<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:icon="@drawable/icona"
android:label="@string/app_name" >
<activity
android:name="com.kurtis.myapp.Home"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kurtis.myapp.Mapexample"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="portrait" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaXXXXXXXXXXXXXXXXXXXXXXXXXq9M" />
</application>
</manifest>
活动:
package com.kurtis.myapp;
import com.example.android.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class Mapexample extends FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapexample);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
// The Map is verified. It is now safe to manipulate the map.
}
}
}
}
...和布局:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
你有解决这个问题的想法吗?
PS对不起我的英语不好...