Android 使用Google地图版本2时出错

Android 使用Google地图版本2时出错,android,google-maps,Android,Google Maps,嘿,海,我无法在手机上加载地图,我收到一个错误,无法打开文件阅读,我添加了谷歌播放服务作为图书馆项目;我还将google play services jar添加到我的项目中 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="c

嘿,海,我无法在手机上加载地图,我收到一个错误,无法打开文件阅读,我添加了谷歌播放服务作为图书馆项目;我还将google play services jar添加到我的项目中

AndroidManifest.xml

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

        <uses-sdk
            android:minSdkVersion="15"
            android:targetSdkVersion="15" />
        <permission
              android:name="com.example.mapsdemo.permission.MAPS_RECEIVE"
              android:protectionLevel="signature"/>
        <uses-permission android:name="com.example.mapsdemo.permission.MAPS_RECEIVE"/>
        <uses-permission android:name="android.permission.INTERNET"/>
        <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" >
            <activity
                android:name="com.example.mapsdemo.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>
            <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="API KEY"/>
        </application>

    </manifest>
当我在装有安卓4.0.4的galaxy s3上运行此程序时,log cat会给我一个错误:

原木猫 01-25 20:11:45.690:E/(23663):无法打开文件进行读取 01-25 20:11:45.690:E/(23663):无法打开文件进行读取

请帮我解决这个问题。

哦,我的天啊……你的“my MainActivity.java”错了。你没有在里面写任何东西,所以你得到了失败的答案。要显示谷歌地图,至少您的java代码必须包含以下代码,即基本和初始设置

1.**修改“**my MainActivity.java”如下所示

这显示了如何使用地图和地图上的标记创建简单活动。请注意,我们如何处理用户设备上未安装/启用/更新Google Play services APK的可能性

public class MainActivity extends android.support.v4.app.FragmentActivity {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.basic_demo);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }


    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }


    private void setUpMap() {
        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    }
}
2.**修改后,按键盘上的**ctrl+shft+字母“o”保存,然后再次运行~


注意:在运行之前,必须在Android 4.0.3中将构建目标设置为“Googel API”,而不是eclipse中的Android 4.0.3。请检查一下;project此错误消息显然是三星Galaxy S3的副作用,当您未注册数字证书的SHA-1指纹时,您将使用谷歌API控制台为Android Maps API V2签署Android应用程序

例如,我得到了相同的错误:

Log cat 01-25 20:11:45.690: E/(23663): Can't open file for reading
…在我切换到一台新笔记本电脑并忘记将该笔记本电脑上新调试证书的SHA-1添加到Google API控制台之后

要在Windows上为调试证书修复此问题,请打开命令提示符,然后:

cd .android
keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android -v
这将打印出一组文本,您需要在
SHA-1:
输出之后复制文本


然后,按照说明将SHA-1指纹(后跟分号)和应用程序包名称添加到Google API控制台。

在AndroidManifest.xml中,替换“…android:value=“API密钥”“/>使用您自己的API_密钥。我不想透露我的API密钥,所以我只是把API密钥放进去了,因为我已经把实际的API密钥放进了那个部分。在运行之前,你必须在Android 4.0.3中将构建目标设置为“Googel API”,而不是eclipse中的安卓4.0.3。请检查一下;projectLog cat 01-25 20:11:45.690: E/(23663): Can't open file for reading
cd .android
keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android -v