【发布时间】:2014-12-28 00:40:19
【问题描述】:
我有问题。我正在尝试将 Google Map 作为一项新活动添加到我的应用程序中。我已经更改了很多次代码,但是当我想打开包含 Google 地图的活动时,我的应用程序正在关闭。
我正在使用 Android Studio,我正在 Huwei Ascand 上测试我的应用程序。
也许有人会有一些想法。
Logcat(在我尝试使用 Google 地图开启活动时):
12-28 01:19:30.894 28452-28452/com.example.user.elderly2 W/dalvikvm﹕ Refusing to reopen boot DEX '/system/framework/hwframework.jar'
12-28 01:19:31.014 28452-28452/com.example.user.elderly2 I/Google Maps Android API﹕ Google Play services client version: 6587000
12-28 01:19:31.024 28452-28452/com.example.user.elderly2 I/Google Maps Android API﹕ Google Play services package version: 6599034
12-28 01:19:31.234 28452-28455/com.example.user.elderly2 E/dalvikvm﹕ GC_CONCURRENT freed 2505K, 24% free 10764K/14019K, paused 12ms+3ms, total 53ms
12-28 01:19:31.284 28452-28455/com.example.user.elderly2 E/dalvikvm﹕ GC_CONCURRENT freed 810K, 20% free 11341K/14019K, paused 12ms+2ms, total 37ms
12-28 01:19:31.474 28452-28455/com.example.user.elderly2 E/dalvikvm﹕ GC_CONCURRENT freed 800K, 16% free 11822K/14019K, paused 12ms+14ms, total 77ms
12-28 01:19:31.675 28452-28455/com.example.user.elderly2 E/dalvikvm﹕ GC_CONCURRENT freed 400K, 12% free 12434K/14019K, paused 12ms+13ms, total 72ms
12-28 01:19:31.685 28452-28452/com.example.user.elderly2 W/System.err﹕ Invalid int: ""
12-28 01:19:31.815 28452-28455/com.example.user.elderly2 E/dalvikvm﹕ GC_CONCURRENT freed 576K, 10% free 12940K/14279K, paused 2ms+14ms, total 51ms
12-28 01:19:31.935 28452-28455/com.example.user.elderly2 E/dalvikvm﹕ GC_CONCURRENT freed 684K, 10% free 12982K/14407K, paused 2ms+2ms, total 48ms
12-28 01:19:31.995 28452-28452/com.example.user.elderly2 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40d2b438)
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.elderly2" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<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" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- End of copy. -->
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
//Main Activity
<activity
android:name=".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>
//Second activity from which I want to turn Google Maps
<activity
android:name=".Main_Menu_Activity"
android:label="@string/title_activity_main__menu_" >
<intent-filter>
<action android:name="com.example.user.elderly2.Main_Menu_Activity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
// activity with Google Maps
<activity
android:name=".Maps_Activity"
android:label="@string/title_activity_maps_" >
<intent-filter>
<action android:name="com.example.user.elderly2.Maps_Activity" />
<category android:name="android.intent.category.default.DEFAULT" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaS************************TcfaQc"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
activity_maps.XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Maps_activity.java:
package com.example.user.elderly2;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
import org.apache.http.HttpMessage;
public class Maps_Activity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps_);
GoogleMap mMap;
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMap = fm.getMap();
}
}
问题解决了!。 cmets 中的解释!
【问题讨论】:
-
尝试在
activity_maps.xml中将class="com.google.android.gms.maps.SupportMapFragment"替换为android:name="com.google.android.gms.maps.SupportMapFragment",看看是否会有所不同。参见例如this documentation. -
感谢参与,但修改后还是一样的情况。 ;(
-
另外,
setContentView(R.layout.activity_maps_);看起来有一个额外的下划线,它不应该这样做。 -
hymm.. 我现在不明白你的意思是写“堆栈跟踪”。这是从开始到崩溃的 logcat?
-
问题解决了! ;) 我必须将这行代码放在清单文件
<uses-library android:name="com.google.android.maps" />之间<application>....</aplication>
标签: java android google-maps android-activity android-maps-v2