gpt4 book ai didi

Android map 应用程序崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 08:01:36 25 4
gpt4 key购买 nike

我正在尝试创建一个简单的 map View 应用程序。我经历了android developers documentation并复制粘贴 MyActivity.java 类和 activity_main.xml 布局。当我在我的真实设备 (Android v2.3.6) 上启动时,应用程序崩溃了。程序包资源管理器、 list 文件和 logcat 错误如下。

enter image description here

MainActivity.java:

package com.timur.mapapplication;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

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"
android:name="com.google.android.gms.maps.MapFragment"/>

AndroidManifest.xml:

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

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

<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" />

<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.gms.version"
android:value="@integer/google_play_services_version" />

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

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

</manifest>

LOGCAT 错误:

12-18 00:03:05.626: E/AndroidRuntime(18591): FATAL EXCEPTION: main
12-18 00:03:05.626: E/AndroidRuntime(18591): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.timur.mapapplication/com.timur.mapapplication.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.os.Looper.loop(Looper.java:130)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.app.ActivityThread.main(ActivityThread.java:3693)
12-18 00:03:05.626: E/AndroidRuntime(18591): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 00:03:05.626: E/AndroidRuntime(18591): at java.lang.reflect.Method.invoke(Method.java:507)
12-18 00:03:05.626: E/AndroidRuntime(18591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
12-18 00:03:05.626: E/AndroidRuntime(18591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
12-18 00:03:05.626: E/AndroidRuntime(18591): at dalvik.system.NativeStart.main(Native Method)
12-18 00:03:05.626: E/AndroidRuntime(18591): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-18 00:03:05.626: E/AndroidRuntime(18591): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.app.Activity.setContentView(Activity.java:1663)
12-18 00:03:05.626: E/AndroidRuntime(18591): at com.timur.mapapplication.MainActivity.onCreate(MainActivity.java:11)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
12-18 00:03:05.626: E/AndroidRuntime(18591): ... 11 more
12-18 00:03:05.626: E/AndroidRuntime(18591): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.timur.mapapplication-1.apk]
12-18 00:03:05.626: E/AndroidRuntime(18591): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-18 00:03:05.626: E/AndroidRuntime(18591): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-18 00:03:05.626: E/AndroidRuntime(18591): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
12-18 00:03:05.626: E/AndroidRuntime(18591): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
12-18 00:03:05.626: E/AndroidRuntime(18591): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
12-18 00:03:05.626: E/AndroidRuntime(18591): ... 19 more

感谢您的帮助。

最佳答案

当您的 minSdkVersion 设置为 8 时,您正在使用 MapFragment。您应该像这样使用 SupportMapFragment:

<?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"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

另外,只是一个建议,不要发布您的 API key ,它应该对开发该应用程序的任何人保密。

关于Android map 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20645955/

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