android mapView错误

时间:2012-05-24 05:21:31

标签: java android eclipse android-mapview

我从example做同样的事情,但Eclipse返回错误。代码如下:

package hello.google.map;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;

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

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

以下是错误:

*

Description Resource    Path    Location    Type
MapActivity cannot be resolved to a type    HelloGoogleMapsActivity.java    /HelloGoogleMaps/src/hello/google/map   line 7  Java Problem
MapActivity cannot be resolved to a type    HelloGoogleMapsActivity.java    /HelloGoogleMaps/src/hello/google/map   line 13 Java Problem
The import com.google cannot be resolved    HelloGoogleMapsActivity.java    /HelloGoogleMaps/src/hello/google/map   line 3  Java Problem
The import com.google cannot be resolved    HelloGoogleMapsActivity.java    /HelloGoogleMaps/src/hello/google/map   line 4  Java Problem
The method isRouteDisplayed() of type MapsActivity must override a superclass method    HelloGoogleMapsActivity.java    /HelloGoogleMaps/src/hello/google/map   line 18 Java Problem
The method onCreate(Bundle) of type MapsActivity must override a superclass method  HelloGoogleMapsActivity.java    /HelloGoogleMaps/src/hello/google/map   line 11 Java Problem
The method setContentView(int) is undefined for the type MapsActivity   HelloGoogleMapsActivity.java    /HelloGoogleMaps/src/hello/google/map   line 14 Java Problem
The public type MapsActivity must be defined in its own file    HelloGoogleMapsActivity.java    /HelloGoogleMaps/src/hello/google/map   line 7  Java Problem*

为什么呢?我做错了什么?

3 个答案:

答案 0 :(得分:1)

从它的外观来看,你可能会错过两件事。 您忘记将以下内容添加到AndroidManifest.xml

<uses-library android:name="com.google.android.maps" />

或者,您尝试在具有股票Android API而非特殊Google API版本的模拟器上运行它。您需要此Google API版本才能使用地图等功能。

如果您没有它,不用担心,您可以在SDK Manager中下载它。然后,只需创建一个新的AVD并将目标设置为目标API级别的Google API版本。

答案 1 :(得分:0)

在创建

后的setContentview之后使用它
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

并放

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


</app...>

答案 2 :(得分:0)

您的错误日志表明文件名为HelloGoogleMapsActivity.java,但您的班级名称为MapsActivity。你确定你做的是正确的吗?尝试将班级名称更改为HelloGoogleMapsActivity或将文件名更改为MapsActivity。在这两种情况下都要更新您的清单。

根据您的链接,主要活动为MapsActivity,并在文件MapsActivity.java中定义。因此,您可以将文件名设置为MapsActivity.java以匹配示例。