我在API 10上有以下错误:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ter.androidapp/com.ter.androidapp.activities.RootActivity}: android.view.InflateException: Binary XML file line #106: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #106: Error inflating class fragment
这是我加载地图的地方:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mMapViewContainer == null) {
here it crash -> mMapViewContainer = getLayoutInflater().inflate(R.layout.fragment_geoloc_map, null);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview_geolo);
mapFragment.getMapAsync(this);
}
FaceBookShareManager.getInstance().initialize(getString(R.string.facebookId));
getSupportFragmentManager().addOnBackStackChangedListener(this);
if (savedInstanceState == null) {
setupTabBarColors(0);
getSupportFragmentManager().beginTransaction().add(R.id.leftPanelContainer, new StationsSearchFragment(), Constants.TAG_STATION_FRAGMENT).commit();
}
if (getIntent() != null && Constants.WIDGET_STATION_CLICK.equals(getIntent().getAction()) && getIntent().getData() != null) {
displayStationFromWidget(Integer.valueOf(getIntent().getData().getSchemeSpecificPart()));
}
setTrackFromNotif();
checkForTrainFromWidget(getIntent());
if (getIntent() != null && getIntent().getExtras() != null) {
onNewIntent(getIntent());
}
}
这是来自fragment_geoloc_map.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/topLayout"
android:background="@color/transparent" >
<TextView
android:id="@+id/textView_trainNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:padding="5dip"
android:textSize="@dimen/xxLargeText"
android:visibility="gone" />
<RelativeLayout
android:id="@+id/geolocInfoContainer"
android:layout_width="fill_parent"
android:paddingBottom="10dip"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView_title"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_marginBottom="10dp"
android:background="@drawable/btn_rechercher_red"
android:gravity="center"
android:paddingBottom="14dp"
android:paddingTop="14dp"
android:text="@string/selectStation"
android:textColor="@color/white"
android:textSize="@dimen/xxxLargeText"
android:textStyle="bold" />
<TextView
android:id="@+id/textView_choose_radius"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView_refresh_map"
android:layout_alignTop="@+id/imageView_refresh_map"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/textView_radius"
android:gravity="center_vertical"
android:text="@string/radius"
android:textColor="@color/darkGrey"
android:textSize="@dimen/largeText" />
<TextView
android:id="@+id/textView_radius"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView_refresh_map"
android:layout_alignTop="@+id/imageView_refresh_map"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/imageView_refresh_map"
android:background="@color/radiusGrey"
android:drawableBottom="@drawable/ico_triangle_gris"
android:gravity="center_vertical"
android:paddingBottom="5dip"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:text="@string/initial_radius"
android:textColor="@color/radiusTextViewColor"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView_refresh_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView_title"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/imageView_backToList"
android:background="@color/red"
android:padding="8dip"
android:src="@drawable/ico_refresh" />
<ImageView
android:id="@+id/imageView_backToList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView_title"
android:layout_marginRight="10dip"
android:background="@color/red"
android:paddingBottom="8dip"
android:paddingLeft="10dip"
android:paddingRight="9dip"
android:paddingTop="8dip"
android:src="@drawable/ico_list_carte_red" />
</RelativeLayout>
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/mapview_geolo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/geolocInfoContainer" />
</RelativeLayout>
这是来自清单文件:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/mapsAPIv2" />
我已经在API 10,16,22,23上进行了测试。但在API 10中,我遇到了膨胀问题。我没有得到我必须改变的东西
答案 0 :(得分:0)
根据您分享的信息,它似乎不是
fragment_geoloc_map.xml
位于视图层次结构中。
您需要执行以下操作之一:
如果这没有意义,请在您的示例中发布更多代码(活动代码和布局文件)。
<强>更新强>
您需要将生命周期事件从Activity / Fragment委派给MapView。
在委派之前,您无法致电getMapAsync(OnMapReadyCallback)
:
onCreate(Bundle)
onResume()
然后你必须委派:
onPause()
onDestroy()
onSaveInstanceState(Bundle)
onLowMemory()
到MapView以防止内存泄漏和分配。