谷歌地图视图出错



我目前正在做一个包含谷歌地图的应用程序。该xml文件的代码如下所示,但在图形布局中,它显示了一个错误

"缺少样式。是否为此布局选择了正确的主题?使用布局上方的"主题"组合框选择不同的布局,或修复主题样式引用。

在当前主题""中找不到样式"mapViewStyle"

当运行谷歌地图时,它将logcat中的错误显示为

java.lang.RuntimeException:无法启动活动ComponentInfo{com.iqmobi.com/iqmobi.Map}:android.view.InflateException:二进制XML文件行#3:膨胀类com.google.android.maps.MapView 时出错

xml和清单文件在下面给出

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

     <com.google.android.maps.MapView 
     android:id="@+id/myMapView1" 
     android:layout_width="fill_parent"  
     android:layout_height="fill_parent" 
     android:clickable="true" 
     android:apiKey="0mRN-6bSm63hZJtPZSmcjoZAzdCztLnZv-O4SZw" 
     >
     </com.google.android.maps.MapView>  


    </LinearLayout>

manifest.xml

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

<uses-sdk android:minSdkVersion="8" 
          android:targetSdkVersion="9"/>
<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" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:icon="@drawable/iconffff"
    android:label="@string/app_name" >
    <uses-library android:name="com.google.android.maps" />
    <activity
        android:label="@string/app_name"
        android:name="com.iqmobi.Map"
        android:screenOrientation="portrait" 
       >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

您需要将主类扩展为MapActivity

public class Abc 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;
    }
}

将布局更改为RelativeLayout并删除此行</com.google.android.maps.MapView>
这样说,没有布局id,这样说:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.google.android.maps.MapView
          android:id="@+id/myMapView1"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:enabled="true"
                 android:clickable="true"
                 android:apiKey="api key" />
</RelativeLayout>

最新更新