gpt4 book ai didi

android - 使用 Google API V2 时应用程序不断崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 11:17:39 25 4
gpt4 key购买 nike

我正在尝试使用 Google API V2 在我的 Android 应用程序中使用 Google map ;我在我的 HTC desire 手机上试用了该应用程序,但它一直崩溃。我已经尝试将项目构建目标更改为 Android 2.2 和 Android 4.2,但仍然没有成功。我还将 android-support-v4.jar 添加到我的项目中。我试图遵循这些 Link

这是我的代码:

googleMaps.manifest

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

<permission
android:name="com.luiz.googleMaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-permission android:name="com.luiz.googleMaps.permission.MAPS_RECEIVE" />

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

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<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="I have used my keys;com.luiz.googleMaps" />

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

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SuppportMapFragment"/>

主 Activity

package com.luiz.googleMaps;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

import android.os.Bundle;

public class MainActivity extends android.support.v4.app.FragmentActivity {

private GoogleMap map;

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

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
}

LogCat 错误:

12-21 06:08:30.734: D/dalvikvm(7102): GC_EXTERNAL_ALLOC freed 54K, 50% free 2692K/5379K, external 0K/0K, paused 93ms
12-21 06:08:30.754: E/ActivityThread(7102): Failed to inflate
12-21 06:08:30.754: E/ActivityThread(7102): android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-21 06:08:30.754: E/ActivityThread(7102): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.Activity.setContentView(Activity.java:1657)
12-21 06:08:30.754: E/ActivityThread(7102): at com.luiz.googleMaps.MainActivity.onCreate(MainActivity.java:31)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
12-21 06:08:30.754: E/ActivityThread(7102): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 06:08:30.754: E/ActivityThread(7102): at android.os.Looper.loop(Looper.java:130)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-21 06:08:30.754: E/ActivityThread(7102): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 06:08:30.754: E/ActivityThread(7102): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 06:08:30.754: E/ActivityThread(7102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-21 06:08:30.754: E/ActivityThread(7102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-21 06:08:30.754: E/ActivityThread(7102): at dalvik.system.NativeStart.main(Native Method)
12-21 06:08:30.754: E/ActivityThread(7102): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SuppportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-21 06:08:30.754: E/ActivityThread(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
12-21 06:08:30.754: E/ActivityThread(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
12-21 06:08:30.754: E/ActivityThread(7102): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-21 06:08:30.754: E/ActivityThread(7102): ... 19 more
12-21 06:08:30.754: E/ActivityThread(7102): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SuppportMapFragment in loader dalvik.system.PathClassLoader[/data/app/com.luiz.googleMaps-2.apk]
12-21 06:08:30.754: E/ActivityThread(7102): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-21 06:08:30.754: E/ActivityThread(7102): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-21 06:08:30.754: E/ActivityThread(7102): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-21 06:08:30.754: E/ActivityThread(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
12-21 06:08:30.754: E/ActivityThread(7102): ... 22 more
12-21 06:08:30.764: D/AndroidRuntime(7102): Shutting down VM
12-21 06:08:30.764: W/dalvikvm(7102): threadid=1: thread exiting with uncaught exception (group=0x40128560)
12-21 06:08:30.764: E/AndroidRuntime(7102): FATAL EXCEPTION: main
12-21 06:08:30.764: E/AndroidRuntime(7102): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.luiz.googleMaps/com.luiz.googleMaps.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.os.Looper.loop(Looper.java:130)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-21 06:08:30.764: E/AndroidRuntime(7102): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 06:08:30.764: E/AndroidRuntime(7102): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 06:08:30.764: E/AndroidRuntime(7102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-21 06:08:30.764: E/AndroidRuntime(7102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-21 06:08:30.764: E/AndroidRuntime(7102): at dalvik.system.NativeStart.main(Native Method)
12-21 06:08:30.764: E/AndroidRuntime(7102): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-21 06:08:30.764: E/AndroidRuntime(7102): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.Activity.setContentView(Activity.java:1657)
12-21 06:08:30.764: E/AndroidRuntime(7102): at com.luiz.googleMaps.MainActivity.onCreate(MainActivity.java:31)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
12-21 06:08:30.764: E/AndroidRuntime(7102): ... 11 more
12-21 06:08:30.764: E/AndroidRuntime(7102): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SuppportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-21 06:08:30.764: E/AndroidRuntime(7102): ... 19 more
12-21 06:08:30.764: E/AndroidRuntime(7102): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SuppportMapFragment in loader dalvik.system.PathClassLoader[/data/app/com.luiz.googleMaps-2.apk]
12-21 06:08:30.764: E/AndroidRuntime(7102): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-21 06:08:30.764: E/AndroidRuntime(7102): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-21 06:08:30.764: E/AndroidRuntime(7102): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
12-21 06:08:30.764: E/AndroidRuntime(7102): ... 22 more
12-21 06:08:36.299: I/Process(7102): Sending signal. PID: 7102 SIG: 9
12-21 06:18:46.745: D/dalvikvm(7174): GC_EXTERNAL_ALLOC freed 55K, 50% free 2691K/5379K, external 0K/0K, paused 45ms
12-21 06:18:46.765: E/ActivityThread(7174): Failed to inflate
12-21 06:18:46.765: E/ActivityThread(7174): android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-21 06:18:46.765: E/ActivityThread(7174): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.Activity.setContentView(Activity.java:1657)
12-21 06:18:46.765: E/ActivityThread(7174): at com.luiz.googleMaps.MainActivity.onCreate(MainActivity.java:15)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
12-21 06:18:46.765: E/ActivityThread(7174): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 06:18:46.765: E/ActivityThread(7174): at android.os.Looper.loop(Looper.java:130)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-21 06:18:46.765: E/ActivityThread(7174): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 06:18:46.765: E/ActivityThread(7174): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 06:18:46.765: E/ActivityThread(7174): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-21 06:18:46.765: E/ActivityThread(7174): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-21 06:18:46.765: E/ActivityThread(7174): at dalvik.system.NativeStart.main(Native Method)
12-21 06:18:46.765: E/ActivityThread(7174): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SuppportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-21 06:18:46.765: E/ActivityThread(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
12-21 06:18:46.765: E/ActivityThread(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
12-21 06:18:46.765: E/ActivityThread(7174): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-21 06:18:46.765: E/ActivityThread(7174): ... 19 more
12-21 06:18:46.765: E/ActivityThread(7174): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SuppportMapFragment in loader dalvik.system.PathClassLoader[/data/app/com.luiz.googleMaps-1.apk]
12-21 06:18:46.765: E/ActivityThread(7174): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-21 06:18:46.765: E/ActivityThread(7174): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-21 06:18:46.765: E/ActivityThread(7174): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-21 06:18:46.765: E/ActivityThread(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
12-21 06:18:46.765: E/ActivityThread(7174): ... 22 more
12-21 06:18:46.775: D/AndroidRuntime(7174): Shutting down VM
12-21 06:18:46.775: W/dalvikvm(7174): threadid=1: thread exiting with uncaught exception (group=0x40128560)
12-21 06:18:46.775: E/AndroidRuntime(7174): FATAL EXCEPTION: main
12-21 06:18:46.775: E/AndroidRuntime(7174): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.luiz.googleMaps/com.luiz.googleMaps.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.os.Looper.loop(Looper.java:130)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-21 06:18:46.775: E/AndroidRuntime(7174): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 06:18:46.775: E/AndroidRuntime(7174): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 06:18:46.775: E/AndroidRuntime(7174): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-21 06:18:46.775: E/AndroidRuntime(7174): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-21 06:18:46.775: E/AndroidRuntime(7174): at dalvik.system.NativeStart.main(Native Method)
12-21 06:18:46.775: E/AndroidRuntime(7174): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-21 06:18:46.775: E/AndroidRuntime(7174): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.Activity.setContentView(Activity.java:1657)
12-21 06:18:46.775: E/AndroidRuntime(7174): at com.luiz.googleMaps.MainActivity.onCreate(MainActivity.java:15)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
12-21 06:18:46.775: E/AndroidRuntime(7174): ... 11 more
12-21 06:18:46.775: E/AndroidRuntime(7174): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SuppportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-21 06:18:46.775: E/AndroidRuntime(7174): ... 19 more
12-21 06:18:46.775: E/AndroidRuntime(7174): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SuppportMapFragment in loader dalvik.system.PathClassLoader[/data/app/com.luiz.googleMaps-1.apk]
12-21 06:18:46.775: E/AndroidRuntime(7174): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-21 06:18:46.775: E/AndroidRuntime(7174): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-21 06:18:46.775: E/AndroidRuntime(7174): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
12-21 06:18:46.775: E/AndroidRuntime(7174): ... 22 more
12-21 06:23:46.827: I/Process(7174): Sending signal. PID: 7174 SIG: 9

最佳答案

您是否尝试过使用 MapFragment 而不是 SupportMapFragment。

我的主要 Activity 是这样的

public class MapActivity extends Activity {

private GoogleMap mMap;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapactivity);
this.getActionBar().setTitle("Map");

getActionBar().setDisplayHomeAsUpEnabled(true);

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


}

关于android - 使用 Google API V2 时应用程序不断崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13985492/

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