2013-11-09 77 views
1

我试图运行在实际设备谷歌地图上运行谷歌地图有Android版本4.0.3 ICE sandwitch,我读了很多的教程和每一个设置都OK,如: 制作安装谷歌在SDK马槽发挥服务队。 在我的应用程序中导入google play服务库。获取谷歌地图API密钥的 。实际设备

清单文件中的代码看起来像:

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

<uses-sdk 
    android:minSdkVersion="13" 
    android:targetSdkVersion="15" /> 

<permission 
    android:name="com.example.google_map_application.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature"/> 

<uses-permission android:name="com.example.google_map_application.MAPS_RECEIVE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission   android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIzaSyCoIsr6NxAH_J3NLtkh5YSxQGZAq1gvWW8" /> 
    <activity 
     android:name="com.example.google_map_application.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

XML文件的代码看起来像:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 

<fragment 
    android:id="@+id/map" 
    android:name="com.google.android.gms.maps.MapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

主要活动代码:

package com.example.google_map_application; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 
import android.os.Bundle; 
import android.app.Activity; 
import android.support.v4.app.FragmentActivity; 
import android.view.Menu; 

public class MainActivity extends Activity{ 
private GoogleMap mMap; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 
    mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
    final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097); 
    Marker ciu = mMap.addMarker(new MarkerOptions() .position(CIU).title("My Office")); 


} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 

    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 

} 

}

连续出现这样的错误:

了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.google_map_application/com.example.google_map_application.MainActivity}:android.view。 InflateException:二进制XML文件行#16:错误膨胀类片段。

+0

可能重复的http://stackoverflow.com/questions/6424853/error-inflating-class-fragment – woot

+0

我读它,它不够,错误仍然存​​在。 –

+0

也许你错过了它,它明确指出,你应该使用'FragmentActivity'代替Activity'的'。 – woot

回答

1

试图改变类似于您的谷歌Play业务库的版本,例如目标SDK的东西:

<uses-sdk 
android:minSdkVersion="13" 
android:targetSdkVersion="17" /> 
+0

我试了一下,但还是不行! –

+1

其正确与我合作。 错误在Google_play_services_lib的导入浴中。 –

0

匹配了android:targetSdkVersion使用相同版本的API您已经下载,例如将其更改为17,如果你有downdloaded谷歌API。

相关问题