本文介绍了Android谷歌地图V2给我IllegalStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我完成了在Google上显示的所有步骤,并且我也查找了其他解决方案,但在我结束了这个过程中。
03-07 05:04:48.318:E / AndroidRuntime(21463):致命例外:main
03-07 05:04:48.318:E / AndroidRuntime(21463):Process:com.graft, PID:21463
03-07 05:04:48.318:E / AndroidRuntime(21463):java.lang.RuntimeException:无法启动活动ComponentInfo {com.graft / com.graft.MainActivity}:android.view。 InflateException:二进制XML文件行#13:错误膨胀类片段
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-07 05:04:48.318:E / AndroidRuntime 21463):at android.app.ActivityThread.access $ 800(ActivityThread.java:135)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.app.ActivityThread $ H .handleMessage(ActivityThread.java:1196)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.os.Handler.dispatchMessage(Handler.java:102)
03- 07 05:04:48.318:E / AndroidRuntime(21463):在android.os.Looper.loop(Looper.java:136)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.app.ActivityThread.main(ActivityThread.java:5017)
03-07 05:04:48.318:E / AndroidRuntime(21463):at java.lang.reflect.Method.invokeNative(Native Method)
03-07 05:04:48.318:E / AndroidRuntime(21463):at java.lang.reflect.Method.invoke(Method.java:515)
03-07 05:04:48.318:E / AndroidRuntime(21463):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
03-07 05:04:48.318:E / AndroidRuntime(21463):at com.android .internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-07 05:04:48.318:E / AndroidRuntime(21463):at dalvik.system.NativeStart.main(Native Method)
03-07 05:04:48.318:E / AndroidRuntime(21463):造成者:android.vi ew.InflateException:二进制XML文件行#13:错误膨胀类片段
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
03-07 05:04:48.318:E / AndroidRuntime(21463):在android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-07 05:04:48.318:E / AndroidRuntime(21463):在android.view.LayoutInflater.inflate(LayoutInflater .java:397)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-07 05:04 :48.318:E / AndroidRuntime(21463):at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
03-07 05:04:48.318:E / AndroidRuntime(21463) :at android.app.Activity.setContentView(Activity.java:1929)
03-07 05:04:48.318:E / AndroidRuntime(21463):at com.graft.MainActivi ty.onCreate(MainActivity.java:27)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.app.Activity.performCreate(Activity.java:5231)
03 -07 05:04:48.318:E / AndroidRuntime(21463):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-07 05:04:48.318:E / AndroidRuntime(21463) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-07 05:04:48.318:E / AndroidRuntime(21463):... 11 more
03-07 05:04 :48.318:E / AndroidRuntime(21463):引起:java.lang.IllegalStateException:应用程序的AndroidManifest.xml中的元数据标记没有正确的值。预计4242000,但找到0.您必须在< application>元素:< meta-data android:name =com.google.android.gms.versionandroid:value =@ integer / google_play_services_version/>
03-07 05:04:48.318:E / AndroidRuntime(21463):at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-07 05:04:48.318 :E / AndroidRuntime(21463):at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-07 05:04:48.318:E / AndroidRuntime(21463):at com.google .android.gms.maps.internal.qv(Unknown Source)
03-07 05:04:48.318:E / AndroidRuntime(21463):at com.google.android.gms.maps.internal.qu(Unknown来源)
03-07 05:04:48.318:E / AndroidRuntime(21463):at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-07 05:04 :48.318:E / AndroidRuntime(21463):at com.google.android.gms.maps.MapFragment $ b.ex(Unknown Source)
03-07 05:04:48.318:E / AndroidRuntime(21463): at com.google.android.gms.maps.MapFragment $ ba(Unknown Source)
03-07 05:04:48.318:E / AndroidRuntime(21463):at com.google.android.gms.dynamic.aa (未知来源)
03-07 05:04:48.318: E / AndroidRuntime(21463):at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-07 05:04:48.318:E / AndroidRuntime(21463):com.google。 android.gms.maps.MapFragment.onInflate(Unknown Source)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.app.Activity.onCreateView(Activity.java:4785)
03-07 05:04:48.318:E / AndroidRuntime(21463):at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
03-07 05:04:48.318:E / AndroidRuntime 21463):... 21 more
Manifest.XML
<?xml version =1.0encoding =utf-8?>
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =com.graft
android:versionCode =1
android:versionName =1.0>
< permission
android:name =com.graft.permission.MAPS_RECEIVE
android:protectionLevel =signature>< / permission>
< permission android:name =com.graft.permission.MEDIA_CONTENT_CONTROL
android:protectionLevel =签名>< / permission>
< uses-permission android:name =com.graft.permission.MAPS_RECEIVE/>
< uses-permission android:name =android.permission.INTERNET/>
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用权限android:name =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<使用权限android:name =android.permission.ACCESS_COARSE_LOCATION/>
< uses-permission android:name =android.permission.ACCESS_FINE_LOCATION/>
< uses-feature android:glEsVersion =0x00020000android:required =true/>
< uses-sdk
android:minSdkVersion =8
android:targetSdkVersion =19/>
< application
android:allowBackup =true
android:icon =@ drawable / ic_launcher
android:label =@ string / app_name
android:theme =@ style / AppTheme
>
< uses-library android:name =com.google.android.maps/>
< meta-data
android:name =com.google.android.maps.v2.API_KEY
android:value =keyhere/>
< activity
android:name =com.graft.MainActivity
android:label =@ string / app_name>
< intent-filter>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< meta-data android:name =com.google.android.gms.verson
android:value =@ integer / google_play_services_version/>
< / application>
Main.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
工具:context =。MainActivity>
< TextView
android:layout_width =wrap_content
android:layout_height =wrap_content
android:layout_centerHorizontal =true
android: layout_centerVertical =true
android:text =@ string / hello_world/>
<片段
android:id =@ + id / map
android:layout_width =match_parent
android:layout_height =match_parent
android: name =com.google.android.gms.maps.SupportMapFragment
class =com.google.android.gms.maps.MapFragment/>
< / RelativeLayout>
MainActivity.java
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
}
解决方案
< manifest ...。>在清单中,我们只需要以下内容来显示Google地图:
< 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/>
<使用权限android:name =com.google.android.providers.gsf.permission.READ_GSERVICES/>
< application ...。>
< activity ... />
< meta-data android:name =com.google.android.gms.versionandroid:value =@ integer / google_play_services_version/>
< meta-data android:name =com.google.android.maps.v2.API_KEYandroid:value =your api key/>
< / application>
< uses-feature android:glEsVersion =0x00020000android:required =true/>
< / manifest>
更改您的片段标记为:
<$ p $ b>
< fragment
android:id =@ + id / map
android:layout_width =match_parent
android:layout_height =match_parent
class =com.google.android.gms.maps.SupportMapFragment/>
清理您的项目并运行。
I did all of the Steps that were shown on Google and i also looked up other solution but in the i end up with this.
03-07 05:04:48.318: E/AndroidRuntime(21463): FATAL EXCEPTION: main
03-07 05:04:48.318: E/AndroidRuntime(21463): Process: com.graft, PID: 21463
03-07 05:04:48.318: E/AndroidRuntime(21463): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.graft/com.graft.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.os.Handler.dispatchMessage(Handler.java:102)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.os.Looper.loop(Looper.java:136)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-07 05:04:48.318: E/AndroidRuntime(21463): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 05:04:48.318: E/AndroidRuntime(21463): at java.lang.reflect.Method.invoke(Method.java:515)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-07 05:04:48.318: E/AndroidRuntime(21463): at dalvik.system.NativeStart.main(Native Method)
03-07 05:04:48.318: E/AndroidRuntime(21463): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.Activity.setContentView(Activity.java:1929)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.graft.MainActivity.onCreate(MainActivity.java:27)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.Activity.performCreate(Activity.java:5231)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-07 05:04:48.318: E/AndroidRuntime(21463): ... 11 more
03-07 05:04:48.318: E/AndroidRuntime(21463): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.maps.MapFragment$b.ex(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.dynamic.a.a(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.app.Activity.onCreateView(Activity.java:4785)
03-07 05:04:48.318: E/AndroidRuntime(21463): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
03-07 05:04:48.318: E/AndroidRuntime(21463): ... 21 more
Manifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.graft"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.graft.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<permission android:name = "com.graft.permission.MEDIA_CONTENT_CONTROL"
android:protectionLevel="signature"></permission>
<uses-permission android:name= "com.graft.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"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="keyhere"/>
<activity
android:name="com.graft.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.verson"
android:value ="@integer/google_play_services_version"/>
</application>
Main.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"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
class="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
MainActivity.java
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
}
I really want to understand what I am doing wrong that way i can actually learn to solve these kinds of things by myself.
解决方案
In Manifest we require only the following things to show google map:
<manifest ….>
<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" />
<application ….>
<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="your api key" />
</application>
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
</manifest>
Change your fragment tag as:
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Clean your project and run.
这篇关于Android谷歌地图V2给我IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!