0
我見過很多相關的問題,但我無法發現我做錯了什麼。我很感激任何人都可以幫助我。當我只向LinearLayout添加一個MapView時,地圖工作正常。但是,當我嘗試添加一個按鈕或textView或佈局中的任何東西在運行時崩潰!如何在LinearLayout中添加MapView和其他組件?
我有三個單獨的fragments
。第一個是所謂的FragmentA.java和Fragment_a.xml
這裏是Fragment_a.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.maps.MapView android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<Button android:id="@+id/googlemaps_select_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Select"/>
</RelativeLayout>
這裏是
FragmentA.java
我不知道如果
View v = inflater.inflate(R.layout.fragment_a, container, false);
是正確的。 fragment_a,正如我所說的是包含完整的視圖片段的名稱:
public class FragmentA extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_a, container, false);
// Gets the MapView from the XML layout and creates it
mapView = (MapView) v.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
MapsInitializer.initialize(this.getActivity());
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
map.animateCamera(cameraUpdate);
return v;
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
我得到了它說的錯誤,inflate exception binary xml file line #10 error inflating class fragment.
09-22 14:43:51.301: E/AndroidRuntime(2164): FATAL EXCEPTION: main
09-22 14:43:51.301: E/AndroidRuntime(2164): Process: com.ass3.journeytracker, PID: 2164
09-22 14:43:51.301: E/AndroidRuntime(2164): android.view.InflateException: Binary XML file line #11: Error inflating class com.google.android.maps.MapView
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-22 14:43:51.301: E/AndroidRuntime(2164): at com.ass3.journeytracker.FragmentA.onCreateView(FragmentA.java:33)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.View.measure(View.java:16497)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.View.measure(View.java:16497)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-22 14:43:51.301: E/AndroidRuntime(2164): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.View.measure(View.java:16497)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-22 14:43:51.301: E/AndroidRuntime(2164): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.View.measure(View.java:16497)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.Choreographer.doFrame(Choreographer.java:544)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.os.Handler.handleCallback(Handler.java:733)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.os.Handler.dispatchMessage(Handler.java:95)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.os.Looper.loop(Looper.java:136)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-22 14:43:51.301: E/AndroidRuntime(2164): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 14:43:51.301: E/AndroidRuntime(2164): at java.lang.reflect.Method.invoke(Method.java:515)
09-22 14:43:51.301: E/AndroidRuntime(2164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-22 14:43:51.301: E/AndroidRuntime(2164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-22 14:43:51.301: E/AndroidRuntime(2164): at dalvik.system.NativeStart.main(Native Method)
09-22 14:43:51.301: E/AndroidRuntime(2164): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.maps.MapView" on path: DexPathList[[zip file "/data/app/com.ass3.journeytracker-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.ass3.journeytracker-2, /vendor/lib, /system/lib]]
09-22 14:43:51.301: E/AndroidRuntime(2164): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-22 14:43:51.301: E/AndroidRuntime(2164): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
09-22 14:43:51.301: E/AndroidRuntime(2164): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
09-22 14:43:51.301: E/AndroidRuntime(2164): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
09-22 14:43:51.301: E/AndroidRuntime(2164): ... 43 more
請發佈整個堆棧跟蹤。 – CommonsWare 2014-09-22 18:03:55
@CommonsWare肯定只有一秒鐘。 – 2014-09-22 18:05:36
@CommonsWare請看看更新 – 2014-09-22 18:33:09