Java 活动启动时应用程序崩溃
我正在创建一个应用程序,在其中我必须在单击按钮时显示地图。但是,当单击map按钮而不是显示map时,应用程序崩溃,并显示“不幸的是,'应用程序'已停止”,这是我的代码: java文件:Java 活动启动时应用程序崩溃,java,android,google-maps-api-2,android-maps-v2,android-permissions,Java,Android,Google Maps Api 2,Android Maps V2,Android Permissions,我正在创建一个应用程序,在其中我必须在单击按钮时显示地图。但是,当单击map按钮而不是显示map时,应用程序崩溃,并显示“不幸的是,'应用程序'已停止”,这是我的代码: java文件: package com.example.jamaattiming; import android.os.Bundle; import android.app.Activity; //import android.app.FragmentTransaction; import android.view.Menu;
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]
(此:0x518786b0)fps:0.88,dur:2279.85,最大值:1974.08,最小值:305.77 04-01
00:32:36.990:V/提供程序/设置(18546):使[系统]无效:当前
214 != 缓存的0 04-01 00:32:37.020:D/ActivityThread(18546):
installProvider:04-01 00:32:37.034:V/提供程序/设置(18546):从
db缓存,名称=已启用声音效果,值=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/资产(18546):资产管理器-->添加默认资产CIP路径
不存在!04-01 00:32:38.741:I/Google地图Android API(18546):
Google Play services客户端版本:4242000 04-01 00:32:39.025:
I/Google地图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):线程ID=1:线程
带未捕获异常退出(组=0x419b19a8)04-01 00:32:39.709:
E/AndroidRuntime(18546):致命异常:main 04-01 00:32:39.709:
E/AndroidRuntime(18546):java.lang.RuntimeException:无法启动
活动
ComponentInfo{com.example.jamat_times/com.example.jamatting.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.Invokenactive(本机方法)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.系统本地启动主(本地方法)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):在
rInflate(LayoutInflater.java:746)04-01
00:32:39.709:E/AndroidRuntime(18546):在
膨胀(LayoutInflater.java:489)04-01
00:32:39.709:E/AndroidRuntime(18546):在
膨胀(LayoutInflater.java:396)04-01
00:32:39.709:E/AndroidRuntime(18546):在
膨胀(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:Maps API需要额外的
要在AndroidManifest.xml中设置以下权限,以确保
正确行为:04-01 00:32:39.709:E/AndroidRuntime(18546):
04-01
00:32:39.709:E/AndroidRuntime(18546):在地图上。E.ci.a(未知来源)
04-01 00:32:39.709:E/AndroidRuntime(18546):在地图上。E.ay.a(未知)
来源)04-01 00:32:39.709:E/AndroidRuntime(18546):at
地图e.ay.a(未知来源)04-01 00:32:39.709:
E/AndroidRuntime(18546):地图E.al.a(未知来源)04-01
00:32:39.709:E/AndroidRuntime(18546):在地图上。E.bh.a(未知来源)
04-01 00:32:39.709:E/AndroidRuntime(18546):在地图上。E.bg.a(未知)
来源)04-01 00:32:39.709:E/AndroidRuntime(18546):at
etu.onTransact(源文件:107)04-01 00:32:39.709:
E/AndroidRuntime(18546):在
android.os.Binder.transact(Bin
Caused by:
java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior: 04-01 00:32:39.709:
E/AndroidRuntime(18546): <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 04-01 00:32:39.709: E/AndroidRuntime(18546): at maps.e.ci.a(Unknown Source)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>