如何在android中解决谷歌地图视图?当我尝试这个程序时,我得到以下错误

时间:2011-12-28 11:48:06

标签: android google-maps-api-3

SampleApplication.java

package com.example;  
    import android.app.Activity;
    import android.os.Bundle;

    public class SampleMapApplication extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);


        }
        protected boolean isRouteDisplayed() 
        {
            return false;
        }
    }

    Main.Xml:
        <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    <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="0U7-rnRk3Os0sPZnZF9iejONnHMsGRLxU0JbrBg"/>
    </LinearLayout>

Manifost文件:                                                                                                                             

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
     <uses-permission android:name="android.permission.INTERNET"/>
    </manifest>

错误:  输出看起来像这样

Source not found..
Thread [<1> main] (Suspended (exception RuntimeException))  
    ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1647    
    ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1663 
    ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 117   
    ActivityThread$H.handleMessage(Message) line: 931   
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 3683    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 507  
    ZygoteInit$MethodAndArgsCaller.run() line: 839  
    ZygoteInit.main(String[]) line: 597 
    NativeStart.main(String[]) line: not available [native method]

1 个答案:

答案 0 :(得分:0)

首先创建新的Android项目并选择目标设备是android google api,而不仅仅是android api。

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:layout_marginTop="10dip"
        android:id="@+id/mapView" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:enabled="true"
        android:clickable="true"
        android:apiKey="02PaBI0a1TZrB-nwZwXYW1u82YKJR0QLD_xDHpA" />
</RelativeLayout>

Java文件: -

public class Display_GoogleMap_Activity extends MapActivity {

    @Override
    protected void onCreate(Bundle icicle) {
        // TODO Auto-generated method stub
        super.onCreate(icicle);
        setContentView(R.layout.google_mapsscreen);
    }

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

试试吧。