当前位置: 首页 > 知识库问答 >
问题:

Android谷歌地图V2停止

罗鸿畴
2023-03-14

我正在尝试建立地图应用程序和遵循这个链接一步一步。我在这里找到了类似的话题,但没有帮助我。我想显示地图,但当我运行它,它返回的力量关闭和我的android设备。我看到了很多关于这个错误的问题,但没有人真正回答我的问题。这是我的logcat:

03-21 20:55:57.476: D/AndroidRuntime(4090): Shutting down VM
03-21 20:55:57.476: W/dalvikvm(4090): threadid=1: thread exiting with uncaught exception (group=0x417692a0)
03-21 20:55:57.500: E/AndroidRuntime(4090): FATAL EXCEPTION: main
03-21 20:55:57.500: E/AndroidRuntime(4090): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapandroid/com.example.mapandroid.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.os.Looper.loop(Looper.java:137)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.main(ActivityThread.java:4895)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at java.lang.reflect.Method.invokeNative(Native Method)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at dalvik.system.NativeStart.main(Native Method)
03-21 20:55:57.500: E/AndroidRuntime(4090): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.example.mapandroid.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:67)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.Activity.performStart(Activity.java:5173)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
03-21 20:55:57.500: E/AndroidRuntime(4090):     ... 11 more
03-21 20:55:57.500: E/AndroidRuntime(4090): 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  element:     
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment$b.ex(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.dynamic.a.a(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-21 20:55:57.500: E/AndroidRuntime(4090):     ... 24 more
03-21 20:55:57.515: D/dalvikvm(4090): GC_CONCURRENT freed 233K, 10% free 7615K/8455K, paused 13ms+2ms, total 39ms
03-21 21:36:53.375: W/dalvikvm(4279): VFY: unable to resolve static field 3202 (MapAttrs) in Lcom/google/android/gms/R$styleable;
03-21 21:36:53.375: D/dalvikvm(4279): VFY: replacing opcode 0x62 at 0x000e
03-21 21:36:53.375: D/AndroidRuntime(4279): Shutting down VM
03-21 21:36:53.375: W/dalvikvm(4279): threadid=1: thread exiting with uncaught exception (group=0x417692a0)
03-21 21:36:53.382: E/AndroidRuntime(4279): FATAL EXCEPTION: main
03-21 21:36:53.382: E/AndroidRuntime(4279): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.example.map.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:57)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.Activity.performStart(Activity.java:5173)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.os.Looper.loop(Looper.java:137)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.main(ActivityThread.java:4895)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at java.lang.reflect.Method.invokeNative(Native Method)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at dalvik.system.NativeStart.main(Native Method)

这里是我的mainactivity.java

package com.example.map;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;


public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            return rootView;
        }
    }

}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.map.MainActivity"
tools:ignore="MergeRootFrame" />
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.map.MainActivity$PlaceholderFragment" >



<fragment
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:id="@+id/map"
    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.map"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<permission android:name="com.example.map.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.map.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"/>

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="0123456789abcde" />

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.map.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>
</application>

</manifest>

我已经从下面链接一步一步地阅读了,但是在我的代码中似乎有很多错误。我错过了什么?有什么建议吗?多谢。

共有1个答案

阳文轩
2023-03-14

com.google.android.gms.r$样式化

这通常是由于没有正确引用google play服务造成的

原因:java.lang.IllegalStateException:应用程序的AndroidManifest.xml中的元数据标记没有正确的值。应为4242000,但找到0。元素中必须有以下声明:

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
 <meta-data
 android:name="com.google.android.maps.v2.API_KEY"
 android:value="your api key"/>
 <meta-data 
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />
 <activity
    android:name="com.example.map.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>
 </application>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="google_play_services_version">4030500</integer>
</resources>

您所需要做的只是引用与

 android:value="@integer/google_play_services_version" /> 
 // this is what should be in the application tag of manifest file
 类似资料:
  • 我的项目内容粘贴在下面。我想我已经有了从所有这些不同的帖子中推荐的一切,但是,像许多其他人一样,我得到了这个通货膨胀运行时错误。 这个实际的项目取自Vogella教程,它甚至不会编译。我从其他帖子中应用了相同问题的修复。 谁能告诉我如何使这工作?有人知道任何地方有一个可行的例子吗?谢谢,加里 清单文件。.. 我的主布局XML文件。... MainActivity.java文件。..(祝代码粘贴在此

  • activity_main.xml 舱单 错误输出

  • 我试图找到android maps api v2的方法,它将决定我在移动时创建的折线的长度。我会把它放在onLocationChanged()中,以便不断更新。有人知道方法是什么吗?maps api将显示哪些单元的长度吗?

  • 所以我看到了一个特殊的例外,我敢肯定的是谷歌地图的绘图代码。 我有一个片段,在那里我以编程方式添加了一个支持地图片段,然后我在其中操纵谷歌地图实例。 这是stacktrace: 我无法可靠地复制它(尽管这种情况经常发生),我已经查看了ReadWriteDirectByteBuffer和ShortToByteBufferAdapter,但没有任何东西突然出现在我面前。 有什么想法吗?

  • 授权失败。请参阅https://developers.google.com/maps/documentation/android/start了解如何正确设置地图。 确保以下内容与API控制台中的内容相对应:包名称:,API密钥:,证书指纹:联系Google服务器失败。建立连接后将进行另一次尝试。 加载地图失败。联系Google服务器时出错。这可能是身份验证问题(但可能是由于网络错误)。 我知道关于

  • 我试图在我的应用程序中添加谷歌地图V2:我已经添加了清单文件中的所有权限 并添加Google play库 但是我发现一个错误,连接谷歌服务器失败,请帮助我