0

我从一个例子做同样的事情,但 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*

为什么?我做错了什么?

4

3 回答 3

1

从外观上看,您可能错过了两件事。要么您忘记将以下内容添加到您的 AndroidManifest.xml

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

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

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

于 2012-05-24T05:31:14.820 回答
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...>
于 2012-05-24T05:37:42.913 回答
0

您的错误日志显示文件名是HelloGoogleMapsActivity.java,但您的类名是MapsActivity. 你确定你在做正确的事吗?尝试将类名更改为HelloGoogleMapsActivity或文件名更改为MapsActivity. 在这两种情况下更新您的清单。

根据您的链接,主要活动是MapsActivity并且在文件中定义MapsActivity.java。因此,您可以更改文件名MapsActivity.java以匹配示例。

于 2012-05-24T06:02:05.477 回答