gpt4 book ai didi

java - Android Google Maps API v2 的问题(

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:58 24 4
gpt4 key购买 nike

我一直在尝试在 Eclipse 中创建 Google Maps API v2 应用程序,但不断遇到一系列错误,我不确定如何解决。

几天前开始编写 Android 应用程序(大约两周前开始编写代码),所以这对我来说仍然很新。

我获得了 SHA 和 MD5、API v2 key ,并通过 Google 进行了注册等。

我不知道我哪里错了!

这是尝试作为 Android 应用程序运行时的 CatLog:

>11-18 16:02:19.756: E/Trace(16453): error opening trace file: No such file or directory (2)
>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapUtilization:0.25

>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapIdealFree:8388608

>11-18 16:02:19.756: D/ActivityThread(16453): setTargetHeapConcurrentStart:2097152

>11-18 16:02:19.816: W/dalvikvm(16453): threadid=1: thread exiting with uncaught exception (group=0x412b5438)

>11-18 16:02:19.826: E/AndroidRuntime(16453): FATAL EXCEPTION: main

>11-18 16:02:19.826: E/AndroidRuntime(16453): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.deliveryfor/com.deliveryfor.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2081)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at
android.app.ActivityThread.access$600(ActivityThread.java:138)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204
)
>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.os.Handler.dispatchMessage(Handler.java:99)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.os.Looper.loop(Looper.java:137)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread.main(ActivityThread.java:4921)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at java.lang.reflect.Method.invokeNative(Native Method)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at java.lang.reflect.Method.invoke(Method.java:511)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at dalvik.system.NativeStart.main(Native Method)

>11-18 16:02:19.826: E/AndroidRuntime(16453): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:398)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.Activity.setContentView(Activity.java:2087)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.deliveryfor.MainActivity.onCreate(MainActivity.java:24)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.Activity.performCreate(Activity.java:5234)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)

>11-18 16:02:19.826: E/AndroidRuntime(16453): ... 11 more

>11-18 16:02:19.826: E/AndroidRuntime(16453): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 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" />

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.internal.q.v(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.internal.q.u(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.dynamic.a.a(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.app.Activity.onCreateView(Activity.java:4889)

>11-18 16:02:19.826: E/AndroidRuntime(16453): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-18 16:02:19.826: E/AndroidRuntime(16453): ... 21 more

说实话,我不知道如何从那个巨大的红色 block 中推断出任何解决方案。以下是我的项目的要素:

主要 Activity :

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends Activity {
private final LatLng LOCATION_STATE = new LatLng(49.27645, -122.917587);
private final LatLng LOCATION_CITY = new LatLng(49.187500, -122.849000);
private final LatLng LOCATION_YOU = new LatLng(49.187500, -122.849000);

private GoogleMap map;

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

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

map.addMarker(new MarkerOptions().position(LOCATION_YOU).title("This is you!"));
}

@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;
}

public void onClick_State(View v) {
// CameraUpdate update = CameraUpdateFactory.newLatLng(LOCATION_BURNABY);
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_YOU, 9);
map.animateCamera(update);
}
public void onClick_City(View v) {
map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_CITY, 14);
map.animateCamera(update);

}
public void onClick_You(View v) {
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_STATE, 20);
map.animateCamera(update);

}

}

activity_main.java

<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity" >

<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/header" />

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="You"
android:onClick="onClick_You"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:id="@+id/btnYou"/>

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="City"
android:onClick="onClick_City"
android:layout_alignParentTop="true"
android:id="@+id/btnCity"
android:layout_centerHorizontal="true"/>

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="State"
android:onClick="onClick_State"
android:layout_alignParentTop="true"
android:id="@+id/btnState"
android:layout_alignParentLeft="true"/>



</RelativeLayout>

AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deliveryfor"
android:versionCode="1"
android:versionName="1.0" >

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

<uses-permission android:name="com.deliveryfor.permission.MAPS_RECEIVE"/>
<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"/>
<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"
android:debuggable="true">

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

<activity
android:name="com.deliveryfor.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>

最佳答案

要测试您的应用程序,您还必须设置 Google Play Services SDK,请参阅此 link并将此标签添加到您的 list 文件中:

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

您的 logcat 指向此:

>11-18 16:02:19.826: E/AndroidRuntime(16453): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  
Expected 4030500 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" />

关于java - Android Google Maps API v2 的问题(,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20058234/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com