好的,伙计们,我有一个问题。我正在尝试将 MapFragment 和 View 放在 FrameLayout 中。听起来很基本,但我做不到。我不断得到这个:
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;
}
}
提前致谢。