com.google.android.maps.MapView类膨胀错误

17

我只是在按照一个简单的地图教程 http://developer.android.com/resources/tutorials/views/hello-mapview.html ,但是遇到了这个错误。我是 Android 新手,尝试过互联网上提供的所有解决方案,但仍未成功。请帮帮我。我下面附上我的主 .xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="***"
/>

而且manifest文件就是这个


主文件和清单文件在哪里? - Vijaya
你具体遇到了什么错误? - Felix
请清楚地解释错误信息,以便他人能够帮助您。 - Lavanya
2
请选择答案 - Bobs
9个回答

52

我遇到了这个问题,并通过以下两个步骤解决:

1)将以下行放在AndroidManifest.xml文件的application(重要)元素中。

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

2) 继承 MapActivity 而不是 Activity。

享受!


2
笨啊,我忘记扩展MapActivity了。 - Warpzit
请注意:MapActivity已经被弃用。现在,我们需要使用MapFragment(或SupportMapFragment)代替。 - gMale

12

您是否将主类扩展为MapActivity?

public class a 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() {
        // TODO Auto-generated method stub
        return false;
    }
}

5
我遇到了同样的问题,经过三个小时的搜索,我做了以下操作来解决它,都在清单文件中。
1)在我的清单文件中,这段代码没有放在正确的位置。
    <uses-library android:name="com.google.android.maps" /> 

它应该在这里,在下面

    <application>

就像这样

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.example.package.name">
      ...
      <application android:name="MyApplication" >
        <uses-library android:name="com.google.android.maps" />
        ...
      </application>
      ...
    </manifest>

2) 我的清单中有一个时期丢失了

    <activity 
        android:name="MyClass" //*****should be android:name=".MyClass"***
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MyClass />

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

3) 我没有指定最小的SDK版本,该版本应放置在

    <manifest> 

代码:

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

4) 要在eclipse的调试模式下让地图正常工作,请按照以下步骤在您的cmd或终端中执行:http://www.buzztouch.com/resources/Obtaining_a_Google_Maps_API_Key_v1.0.pdf

希望这能帮到某些人。


3
我有同样的问题。只需扩展MapActivity而不是Activity即可。

1

除了使用标签外,还要使用谷歌地图进行工作

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

in the tag, use another tag

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

在标签内完成即可。

但请记住,您应该在与Google Inc. API兼容的AVD中运行此应用程序,而不是Android API。

另一个重要的事情是,请确保您正在使用MD5 API密钥,而不是SHA1或任何其他协议API密钥。


1

将此代码插入到MapView的xml声明中

xmlns:android="http://schemas.android.com/apk/res/android"

1

你正在运行应用程序的模拟器上没有谷歌地图 jar 包。因此,请从 Google API 创建模拟器并在那里运行你的应用程序。

请参考以下图片创建带有 Google API 的模拟器。

enter image description here


1

我知道以下内容不是原问题提问者的错误 - 但由于我的问题导致了相同的错误消息,我想我也可以将其添加进来,以防将来有人遇到类似问题。

我检查了所有其他好的提示,但在我的项目中没有缺失任何一个。

最终解决我的问题的是,我忘记在布局中声明MapView,包括完整的包名称。无论是Eclipse还是Lint都没有告诉我这一点:

<com.google.android.maps.MapView
    ...
    />

您的帖子对我非常有帮助。 非常感谢。 - raghav chopra

0
即使按照上述所有步骤操作,如果没有为 MapView 指定 api-key,也会出现此异常。只需添加你从谷歌获得的 api-key 即可解决。
<com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" 
         android:apiKey = "api-key_goes_here"
  >

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接