gpt4 book ai didi

android - 类 fragment 膨胀错误(使用谷歌地图 android api v2)

转载 作者:太空狗 更新时间:2023-10-29 16:20:05 25 4
gpt4 key购买 nike

我无法从开发人员站点运行此示例,并且卡住了(可能是一些简单的东西)这是我的 xml 布局

<?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"
tools:context=".MainActivity" >

<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

我的主要 Activity

    package PackageName.AndroidMapsTest;
import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_test_1);
}
}

和我的 list

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

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

<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<permission
android:name="Pakagename.AndroidMapsTest.permission.MAPS_RECIVE"
android:protectionLevel="signature" />
<uses-permission android:name="Pakagename.AndroidMapsTest.permission.MAPS_RECIVE"/>

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

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

<activity
android:name="edu.lewisu.cs.shanejmiller.AndroidMapsTest.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.maps.v2.API_KEY"
android:value="my_api_key" />

</application>

</manifest>

我从 log cat 得到的错误是

java.lang.RunTimeException: Unable to start activity ComponentInfo{packagename.AndroidMapsTest/packagename.AndroidMapsTest.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment 

我现在已经被困了一段时间,希望得到任何帮助。提前致谢

日志跟踪

07-05 22:00:55.633: E/AndroidRuntime(1799): FATAL EXCEPTION: main
07-05 22:00:55.633: E/AndroidRuntime(1799): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.lewisu.cs.shanejmiller.AndroidMapsTest/edu.lewisu.cs.shanejmiller.AndroidMapsTest.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.os.Looper.loop(Looper.java:137)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-05 22:00:55.633: E/AndroidRuntime(1799): at java.lang.reflect.Method.invokeNative(Native Method)
07-05 22:00:55.633: E/AndroidRuntime(1799): at java.lang.reflect.Method.invoke(Method.java:511)
07-05 22:00:55.633: E/AndroidRuntime(1799): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-05 22:00:55.633: E/AndroidRuntime(1799): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-05 22:00:55.633: E/AndroidRuntime(1799): at dalvik.system.NativeStart.main(Native Method)
07-05 22:00:55.633: E/AndroidRuntime(1799): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-05 22:00:55.633: E/AndroidRuntime(1799): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.Activity.setContentView(Activity.java:1881)
07-05 22:00:55.633: E/AndroidRuntime(1799): at edu.lewisu.cs.shanejmiller.AndroidMapsTest.MainActivity.onCreate(MainActivity.java:15)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.Activity.performCreate(Activity.java:5104)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-05 22:00:55.633: E/AndroidRuntime(1799): ... 11 more
07-05 22:00:55.633: E/AndroidRuntime(1799): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.Fragment.instantiate(Fragment.java:592)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.Fragment.instantiate(Fragment.java:560)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.Activity.onCreateView(Activity.java:4709)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
07-05 22:00:55.633: E/AndroidRuntime(1799): ... 21 more
07-05 22:00:55.633: E/AndroidRuntime(1799): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: /data/app/edu.lewisu.cs.shanejmiller.AndroidMapsTest-2.apk
07-05 22:00:55.633: E/AndroidRuntime(1799): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-05 22:00:55.633: E/AndroidRuntime(1799): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-05 22:00:55.633: E/AndroidRuntime(1799): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-05 22:00:55.633: E/AndroidRuntime(1799): at android.app.Fragment.instantiate(Fragment.java:582)
07-05 22:00:55.633: E/AndroidRuntime(1799): ... 24 more

最佳答案

您正在尝试将 com.google.android.gms.maps.MapFragment(用于 native API 级别 11+ fragment )与 FragmentActivity(用于 Android 支持向后移植)一起使用 fragment )。那些需要匹配。由于您的 android:minSdkVersion 是 12,因此将 FragmentActivity 更改为 Activity

关于android - 类 fragment 膨胀错误(使用谷歌地图 android api v2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17496055/

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