图形页面坠毁在Android的API V2 [英] Mapview crashed in android api v2
问题描述
我试图创建采用了android API V2一个图形页面。但是,我的应用程序得到坠毁在设备中。但在仿真器工作不崩溃
这是我得到的主要错误。我找不出什么问题。请帮帮我。
我用的教程从androidhive。
Android清单
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.samplemap
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =12
机器人:targetSdkVersion =17/> <许可
机器人:名字=com.example.samplemap.permission.MAPS_RECEIVE
安卓的ProtectionLevel =签名/> <用途特征
机器人:glEsVersion =0x00020000
机器人:要求=真/> <使用许可权的android:NAME =com.example.samplemap.permission.MAPS_RECEIVE/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/> <应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名字=com.example.samplemap.MainActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
&所述;元数据
机器人:名字=com.google.android.gms.version
机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>
&所述;元数据
机器人:名字=com.google.android.maps.v2.API_KEY
机器人:值=AIzaSyD1F0YSlV2_WqlY9yhJpqfsPP2jrtod_TU/>
< /用途>< /清单>
Activity_main
<
的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。> <片段
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
类=com.google.android.gms.maps.MapFragment/>< / RelativeLayout的>
MainActivity.java
包com.example.samplemap;
进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.MapFragment;进口android.app.Activity;
进口android.os.Bundle;
进口android.widget.Toast;公共类MainActivity延伸活动{
// 谷歌地图
私人GoogleMap的GoogleMap的; @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main); 尝试{
//载入地图
initilizeMap(); }赶上(例外五){
e.printStackTrace();
} } / **
*函数来加载地图。如果地图不创建它会为您创建它
* * /
私人无效initilizeMap(){
如果(GoogleMap的== NULL){
GoogleMap的=((MapFragment)getFragmentManager()。findFragmentById(
R.id.map))的GetMap()。 //检查是否映射成功与否创建
如果(GoogleMap的== NULL){
Toast.makeText(getApplicationContext(),
对不起!无法创建地图,Toast.LENGTH_SHORT)
。显示();
}
}
} @覆盖
保护无效onResume(){
super.onResume();
initilizeMap();
}}
在点击模拟器游戏服务(模拟器中的谷歌地图API V2不会工作),我收到以下错误:
04-17 16:47:47.711:E / AndroidRuntime(1685):致命异常:主要
04-17 16:47:47.711:E / AndroidRuntime(1685):android.content.ActivityNotFoundException:无活动处理意向{行动= android.intent.action.VIEW DAT =市场://详细信息的id = com的? google.android.gms FLG = 0x80000 PKG = com.android.vending}
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.app.Activity.startActivityForResult(Activity.java:3351)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.app.Activity.startActivityForResult(Activity.java:3312)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.app.Activity.startActivity(Activity.java:3522)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.app.Activity.startActivity(Activity.java:3490)
04-17 16:47:47.711:E / AndroidRuntime(1685):在com.google.android.gms.dynamic.a $ 5.onClick(来源不明)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.view.View.performClick(View.java:4084)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.view.View $ PerformClick.run(View.java:16966)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.os.Handler.handleCallback(Handler.java:615)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.os.Handler.dispatchMessage(Handler.java:92)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.os.Looper.loop(Looper.java:137)
04-17 16:47:47.711:E / AndroidRuntime(1685):在android.app.ActivityThread.main(ActivityThread.java:4745)
04-17 16:47:47.711:E / AndroidRuntime(1685):在java.lang.reflect.Method.invokeNative(本机方法)
04-17 16:47:47.711:E / AndroidRuntime(1685):在java.lang.reflect.Method.invoke(Method.java:511)
04-17 16:47:47.711:E / AndroidRuntime(1685):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)
04-17 16:47:47.711:E / AndroidRuntime(1685):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-17 16:47:47.711:E / AndroidRuntime(1685):在dalvik.system.NativeStart.main(本机方法)
您的logcat说清楚
致:java.lang.IllegalStateException:在元数据标签的
应用的AndroidManifest.xml没有正确的价值。结果
java.lang.IllegalStateException:引起你的应用的AndroidManifest.xml元数据标签没有正确的价值。预计4323000但发现0。你必须有该元素中的如下声明:结果
04-17 14:59:51.881:E / AndroidRuntime(1057):
预计4323000但发现0您必须具备以下
元素中声明:
块引用>尝试添加
<元数据>
下的标记<应用>
标记中的的manifest.xml
文件中像<元数据
机器人:名字=com.google.android.gms.version
机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>请您
的manifest.xml
像这样....<应用>
..............
&所述;元数据
机器人:名字=com.google.android.maps.v2.API_KEY
机器人:值=键/><元数据机器人:名字=com.google.android.gms.version
机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>< /用途>I tried to create a mapview using android api v2. But my app got crashed in device. But working in emulator not crashing
These are the main errors i got. I cant figure out whats the problem. Please help me. I used tutorial from androidhive.
Android Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.samplemap" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="12" android:targetSdkVersion="17" /> <permission android:name="com.example.samplemap.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-permission android:name="com.example.samplemap.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" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.samplemap.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.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyD1F0YSlV2_WqlY9yhJpqfsPP2jrtod_TU" /> </application> </manifest>
Activity_main
<
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" tools:context=".MainActivity" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment" /> </RelativeLayout>
MainActivity.java
package com.example.samplemap; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapFragment; import android.app.Activity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends Activity { // Google Map private GoogleMap googleMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { // Loading map initilizeMap(); } catch (Exception e) { e.printStackTrace(); } } /** * function to load map. If map is not created it will create it for you * */ private void initilizeMap() { if (googleMap == null) { googleMap = ((MapFragment) getFragmentManager().findFragmentById( R.id.map)).getMap(); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT) .show(); } } } @Override protected void onResume() { super.onResume(); initilizeMap(); } }
On clicking play service on emulator(google map api v2 wont work in emulator ), I get the following errors:
04-17 16:47:47.711: E/AndroidRuntime(1685): FATAL EXCEPTION: main 04-17 16:47:47.711: E/AndroidRuntime(1685): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.google.android.gms flg=0x80000 pkg=com.android.vending } 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.app.Activity.startActivityForResult(Activity.java:3351) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.app.Activity.startActivityForResult(Activity.java:3312) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.app.Activity.startActivity(Activity.java:3522) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.app.Activity.startActivity(Activity.java:3490) 04-17 16:47:47.711: E/AndroidRuntime(1685): at com.google.android.gms.dynamic.a$5.onClick(Unknown Source) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.view.View.performClick(View.java:4084) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.view.View$PerformClick.run(View.java:16966) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.os.Handler.handleCallback(Handler.java:615) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.os.Handler.dispatchMessage(Handler.java:92) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.os.Looper.loop(Looper.java:137) 04-17 16:47:47.711: E/AndroidRuntime(1685): at android.app.ActivityThread.main(ActivityThread.java:4745) 04-17 16:47:47.711: E/AndroidRuntime(1685): at java.lang.reflect.Method.invokeNative(Native Method) 04-17 16:47:47.711: E/AndroidRuntime(1685): at java.lang.reflect.Method.invoke(Method.java:511) 04-17 16:47:47.711: E/AndroidRuntime(1685): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 04-17 16:47:47.711: E/AndroidRuntime(1685): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 04-17 16:47:47.711: E/AndroidRuntime(1685): at dalvik.system.NativeStart.main(Native Method)
解决方案Your logcat clearly said
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4323000 but found 0. You must have the following declaration within the element:
04-17 14:59:51.881: E/AndroidRuntime(1057): Expected 4323000 but found 0. You must have the following declaration within the element:Try to add
<meta-data>
tag under<application>
tag in yourmanifest.xml
file like<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Make your
manifest.xml
like this....<application> .............. <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="Key" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> </application>
这篇关于图形页面坠毁在Android的API V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!