gpt4 book ai didi

java - Android Google map V2 - 项目已停止工作

转载 作者:行者123 更新时间:2023-12-01 14:19:32 24 4
gpt4 key购买 nike

我正在尝试在我的三星 s3 mini (4.1.2) 上使用谷歌 Android map V2,但是我不断收到消息“应用程序已意外停止”。我已经包含了 google API [Android 4.1.2]、Google play 服务库、android-support-v4.jar。以下是代码:在我的 AndroidManifest.xml 中

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

<permission
android:name="com.Test.projecttest.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-permission android:name="com.Test.projecttest.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" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<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" />

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />

<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="AIzaSyBjT4hZc4gKo1lyrQ5fwLD_Fz5vWgUQmlA" />

<activity
android:name="com.Test.projecttest.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>

</manifest>

com.Test.projecttest 中的 MainActivity.java

      package com.Test.projecttest;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

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

main.xml 位于 res/layout

    <?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />

我的日志猫:

07-19 16:21:46.594: E/AndroidRuntime(5069): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Test.projecttest/com.Test.projecttest.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
07-19 16:21:46.594: E/AndroidRuntime(5069): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
07-19 16:21:46.594: E/AndroidRuntime(5069): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
07-19 16:21:46.594: E/AndroidRuntime(5069): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment

最佳答案

你的 minsdk 是 8

 <uses-sdk
android:minSdkVersion="8"

使用SupportFragment

在布局 xml 中使用以下内容

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

您的 Activity 必须扩展 FragmentActivity

还将其添加到 list 中

    <permission
android:name="com.Test.projecttest.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.Test.projecttest.permission.MAPS_RECEIVE"/>

初始化 map 对象

 SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap();

确保您已添加支持库

另请确保您导入了以下内容

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment;

关于java - Android Google map V2 - 项目已停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17740874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com