gpt4 book ai didi

android - 在 FrameLayout 中添加 Google Maps Android API v2 MapFragment 和 View

转载 作者:行者123 更新时间:2023-11-29 21:44:49 25 4
gpt4 key购买 nike

好的伙计们,我有一个问题。我试图在 FrameLayout 中放置一个 MapFragment 和一个 View 。听起来像是很基本的东西,但我做不到。我不断得到这个:

04-22 17:12:43.261: E/AndroidRuntime(23281): FATAL EXCEPTION: main
04-22 17:12:43.261: E/AndroidRuntime(23281): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testarc/com.example.testarc.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class com.google.android.view.View
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.os.Handler.dispatchMessage(Handler.java:99)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.os.Looper.loop(Looper.java:137)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.ActivityThread.main(ActivityThread.java:5039)
04-22 17:12:43.261: E/AndroidRuntime(23281): at java.lang.reflect.Method.invokeNative(Native Method)
04-22 17:12:43.261: E/AndroidRuntime(23281): at java.lang.reflect.Method.invoke(Method.java:511)
04-22 17:12:43.261: E/AndroidRuntime(23281): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-22 17:12:43.261: E/AndroidRuntime(23281): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-22 17:12:43.261: E/AndroidRuntime(23281): at dalvik.system.NativeStart.main(Native Method)
04-22 17:12:43.261: E/AndroidRuntime(23281): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class com.google.android.view.View
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-22 17:12:43.261: E/AndroidRuntime(23281): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.Activity.setContentView(Activity.java:1881)
04-22 17:12:43.261: E/AndroidRuntime(23281): at com.example.testarc.MainActivity.onCreate(MainActivity.java:32)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.Activity.performCreate(Activity.java:5104)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-22 17:12:43.261: E/AndroidRuntime(23281): ... 11 more
04-22 17:12:43.261: E/AndroidRuntime(23281): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.view.View" on path: /data/app/com.example.testarc-2.apk
04-22 17:12:43.261: E/AndroidRuntime(23281): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-22 17:12:43.261: E/AndroidRuntime(23281): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-22 17:12:43.261: E/AndroidRuntime(23281): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
04-22 17:12:43.261: E/AndroidRuntime(23281): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
04-22 17:12:43.261: E/AndroidRuntime(23281): ... 22 more

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

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

<view
android:id="@+id/myview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.view.View" />
</FrameLayout>

</LinearLayout>

代码如下:

package com.example.testarc;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

public static MapFragment mapFragment;
public static View myView;

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

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

myView = (MyView)findViewById(R.id.myview);
}

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

}

提前致谢。

最佳答案

好的,我明白了,它真的很愚蠢:它是 android.view.View,而不是 com.google.android.view.View……显然。 (今天不是我的日子)

关于android - 在 FrameLayout 中添加 Google Maps Android API v2 MapFragment 和 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16150745/

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