【发布时间】:2014-03-31 20:24:39
【问题描述】:
我正在创建一个应用程序,单击按钮时我必须在其中显示地图。但是当点击地图按钮而不是显示地图时,应用程序崩溃并说“不幸的是,'应用程序'已停止”这是我的代码:
java 文件:
package com.example.jamaattiming;
import android.os.Bundle;
import android.app.Activity;
//import android.app.FragmentTransaction;
import android.view.Menu;
import com.example.jamaat_times.R;
import com.google.android.gms.maps.GoogleMap;
//import com.google.android.gms.maps.MapFragment;
public class TagYourself extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tag_yourself);
/* MapFragment mMapFragment = MapFragment.newInstance();
FragmentTransaction fragmentTransaction =
getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map, mMapFragment);
fragmentTransaction.commit();
GoogleMap maps;
maps=(((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap());*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tag_yourself, menu);
return true;
}
}
这是 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:orientation="vertical"
android:background="#808080">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jamaat_times"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<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_jamaat"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.jamaattiming.Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.jamaattiming.MainPage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.jamaattiming.Qibla"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="com.example.COMPASS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.jamaattiming.JamaatFinder"
android:label="@string/title_activity_jamaat_finder" >
</activity>
<activity
android:name="com.example.jamaattiming.QiblaFinder"
android:label="@string/title_activity_qibla_finder" >
</activity>
<activity
android:name="com.example.jamaattiming.TagYourself"
android:label="@string/title_activity_tag_yourself" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.jamaattiming.NearbySearch"
android:label="@string/title_activity_nearby_search" >
</activity>
<activity
android:name="com.example.jamaattiming.ManualSearch"
android:label="@string/title_activity_manual_search" >
</activity>
</application>
</manifest>
这是日志猫:
04-01 00:32:36.587: I/SurfaceTextureClient(18546): [STC::queueBuffer] (this:0x518786b0) fps:0.88, dur:2279.85, max:1974.08, min:305.77 04-01 00:32:36.990: V/Provider/Settings(18546): 无效 [system]: current 214 != 缓存 0 04-01 00:32:37.020: D/ActivityThread(18546): installProvider: 04-01 00:32:37.034: V/Provider/Settings(18546): 从 数据库缓存,名称 = sound_effects_enabled ,值 = 0 04-01 00:32:37.223: D/mylog(18546): Wifi 状态真 04-01 00:32:38.102: D/ActivityThread(18546):getPackageInfo:securityViolation=true 04-01 00:32:38.102: W/asset(18546): AssetManager-->addDefaultAssets CIP 路径 不存在! 04-01 00:32:38.741: I/Google Maps Android API(18546): Google Play 服务客户端版本:4242000 04-01 00:32:39.025: I/Google Maps Android API(18546):Google Play 服务包 版本:4324034 04-01 00:32:39.538:D/AndroidRuntime(18546):关闭 关闭 VM 04-01 00:32:39.538: W/dalvikvm(18546): threadid=1: thread 以未捕获的异常退出 (group=0x419b19a8) 04-01 00:32:39.709: E/AndroidRuntime(18546): 致命异常: main 04-01 00:32:39.709: E/AndroidRuntime(18546): java.lang.RuntimeException: 无法启动 活动 组件信息{com.example.jamaat_times/com.example.jamaattiming.TagYourself}: android.view.InflateException:二进制 XML 文件第 8 行:错误 膨胀类片段 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.ActivityThread.access$600(ActivityThread.java:162) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.os.Handler.dispatchMessage(Handler.java:107) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.os.Looper.loop(Looper.java:194) 04-01 00:32:39.709: E/AndroidRuntime(18546):在 android.app.ActivityThread.main(ActivityThread.java:5371) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 java.lang.reflect.Method.invokeNative(Native Method) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 java.lang.reflect.Method.invoke(Method.java:525) 04-01 00:32:39.709: E/AndroidRuntime(18546):在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 dalvik.system.NativeStart.main(本机方法)04-01 00:32:39.709: E/AndroidRuntime(18546):引起:android.view.InflateException: 二进制 XML 文件第 8 行:膨胀类片段时出错 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:489) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:396) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:352) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.Activity.setContentView(Activity.java:1881) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 com.example.jamaattiming.TagYourself.onCreate(TagYourself.java:16) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.Activity.performCreate(Activity.java:5122) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 04-01 00:32:39.709: E/AndroidRuntime(18546): ... 11 更多 04-01 00:32:39.709: E/AndroidRuntime(18546): 由: java.lang.SecurityException:地图 API 需要额外的 在 AndroidManifest.xml 中设置以下权限以确保 正确行为:04-01 00:32:39.709:E/AndroidRuntime(18546): 04-01 00:32:39.709:E/AndroidRuntime(18546):在 maps.e.ci.a(未知来源) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 maps.e.ay.a(未知 来源)04-01 00:32:39.709:E/AndroidRuntime(18546):在 maps.e.ay.a(未知来源)04-01 00:32:39.709: E/AndroidRuntime(18546): 在 maps.e.al.a(Unknown Source) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 maps.e.bh.a(未知来源) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 maps.e.bg.a(未知 来源)04-01 00:32:39.709:E/AndroidRuntime(18546):在 etu.onTransact(SourceFile:107) 04-01 00:32:39.709: E/AndroidRuntime(18546):在 android.os.Binder.transact(Binder.java:310) 04-01 00:32:39.709: E/AndroidRuntime(18546):在 com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(未知 来源)04-01 00:32:39.709:E/AndroidRuntime(18546):在 com.google.android.gms.maps.MapFragment$a.onCreateView(未知来源) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 com.google.android.gms.dynamic.a$4.b(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 com.google.android.gms.dynamic.a.a(未知来源)04-01 00:32:39.709: E/AndroidRuntime(18546):在 com.google.android.gms.dynamic.a.onCreateView(Unknown Source) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 com.google.android.gms.maps.MapFragment.onCreateView(未知来源) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.Fragment.performCreateView(Fragment.java:1695) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:861) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137) 04-01 00:32:39.709:E/AndroidRuntime(18546):在 android.app.Activity.onCreateView(Activity.java:4735) 04-01 00:32:39.709: E/AndroidRuntime(18546): 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 04-01 00:32:39.709: E/AndroidRuntime(18546): ... 21 更多
enter code here
【问题讨论】:
-
在提问之前您是否真的阅读过错误信息?
-
我是安卓初学者。我读了它,但无法理解任何东西,这就是我在这里发布它的原因。现在我正在学习在这里阅读错误。
-
在阅读这些错误堆栈跟踪时,发现根本原因很重要。注意
Caused by:部分
标签: java android google-maps-api-2 android-maps-v2 android-permissions