我的谷歌地图出了问题?

时间:2011-11-25 06:47:55

标签: android android-layout android-emulator android-manifest

这里我给我的谷歌地图视图的代码,这是不工作,如果我模拟它将来强制关闭错误,         任何身体都能治愈我,我也会给我的原木猫细节...

1.gmap活动类

    package net.gmaps;

    import android.os.Bundle;

    import com.google.android.maps.MapActivity;
    public class GoogleMapsActivity extends MapActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        MapView mv = (MapView) findViewById(R.id.mapView);
        }

        @Override
        protected boolean isRouteDisplayed() {
            // TODO Auto-generated method stub
            return false;
        }
    }

2.main.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">

        <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="0jEK9Odr895XgKEM5xr-nCr6stwV9dUquFVdsWg"
                     />


    </RelativeLayout>

3.android清单文件

      <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.gmaps"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="com.google.android.maps"/>
        <activity
            android:label="@string/app_name"
            android:name=".GoogleMapsActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>


</manifest>

4.my Logcat详细信息

     11-30 12:28:45.996: D/AndroidRuntime(306): Shutting down VM
11-30 12:28:45.996: W/dalvikvm(306): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
11-30 12:28:45.996: E/AndroidRuntime(306): Uncaught handler: thread main exiting due to uncaught exception
11-30 12:28:46.035: E/AndroidRuntime(306): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
11-30 12:28:46.035: E/AndroidRuntime(306):  at dalvik.system.DexFile.defineClass(Native Method)
11-30 12:28:46.035: E/AndroidRuntime(306):  at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209)
11-30 12:28:46.035: E/AndroidRuntime(306):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
11-30 12:28:46.035: E/AndroidRuntime(306):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-30 12:28:46.035: E/AndroidRuntime(306):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-30 12:28:46.035: E/AndroidRuntime(306):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-30 12:28:46.035: E/AndroidRuntime(306):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
11-30 12:28:46.035: E/AndroidRuntime(306):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
11-30 12:28:46.035: E/AndroidRuntime(306):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-30 12:28:46.035: E/AndroidRuntime(306):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-30 12:28:46.035: E/AndroidRuntime(306):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 12:28:46.035: E/AndroidRuntime(306):  at android.os.Looper.loop(Looper.java:123)
11-30 12:28:46.035: E/AndroidRuntime(306):  at android.app.ActivityThread.main(ActivityThread.java:4363)
11-30 12:28:46.035: E/AndroidRuntime(306):  at java.lang.reflect.Method.invokeNative(Native Method)
11-30 12:28:46.035: E/AndroidRuntime(306):  at java.lang.reflect.Method.invoke(Method.java:521)
11-30 12:28:46.035: E/AndroidRuntime(306):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-30 12:28:46.035: E/AndroidRuntime(306):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-30 12:28:46.035: E/AndroidRuntime(306):  at dalvik.system.NativeStart.main(Native Method)
11-30 12:28:46.085: I/dalvikvm(306): threadid=7: reacting to signal 3
11-30 12:28:46.265: I/dalvikvm(306): Wrote stack trace to '/data/anr/traces.txt'

3 个答案:

答案 0 :(得分:0)

在Android.xml中为您的应用程序添加以下权限。

  • ACCESS_FINE_LOCATION
  • ACCESS_COARSE_LOCATION

尝试一下。

答案 1 :(得分:0)

把这一行

(uses-library android:name="com.google.android.maps")
在android manifest.xml

中的应用程序选项卡的解除之后

答案 2 :(得分:0)

在android清单文件中使用库进入你的aplication标签:

<application android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="com.google.android.maps" />
         <activity ....
         </activity>
</application>

并输入ACCESS_FINE_LOCATION ACCESS_COARSE_LOCATION permisions .... 在onCreate上,你必须像这样定义mapView: 在setContent

之后MapView mapView = (MapView) findViewById(R.id.mapView);