gpt4 book ai didi

android - SupportMapFragment - 二进制 xml 文件行 #2 : Error inflating class fragment

转载 作者:行者123 更新时间:2023-11-29 14:32:01 25 4
gpt4 key购买 nike

我有一个扩展 FragmentActivty 的主类和扩展 SupportMapFragment 的 CustomMapFragment,当我将我的 customMapFragment 调用到 FragmentActivity 中时,我在 logCat 看到这个错误。

LogCat 结果:

01-05 17:43:13.916: D/ERROR(2371): Binary XML file line #2: Error inflating class fragment
01-05 17:43:13.936: W/System.err(2371): android.view.InflateException: Binary XML file line 2: Error inflating class fragment
01-05 17:43:13.936: W/System.err(2371): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
01-05 17:43:13.946: W/System.err(2371): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
01-05 17:43:13.958: W/System.err(2371): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-05 17:43:13.958: W/System.err(2371): at com.main.whereismyfriend.CustomMapFragment .onCreateView(CustomMapFragment .java:48)
01-05 17:43:13.958: W/System.err(2371): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
01-05 17:43:13.958: W/System.err(2371): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
01-05 17:43:13.966: W/System.err(2371): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
01-05 17:43:13.966: W/System.err(2371): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-05 17:43:13.966: W/System.err(2371): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
01-05 17:43:13.976: W/System.err(2371): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
01-05 17:43:14.006: W/System.err(2371): at android.os.Handler.handleCallback(Handler.java:730)
01-05 17:43:14.006: W/System.err(2371): at android.os.Handler.dispatchMessage(Handler.java:92)
01-05 17:43:14.016: W/System.err(2371): at android.os.Looper.loop(Looper.java:137)
01-05 17:43:14.035: W/System.err(2371): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-05 17:43:14.035: W/System.err(2371): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 17:43:14.056: W/System.err(2371): at java.lang.reflect.Method.invoke(Method.java:525)
01-05 17:43:14.066: W/System.err(2371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-05 17:43:14.075: W/System.err(2371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-05 17:43:14.075: W/System.err(2371): at dalvik.system.NativeStart.main(Native Method)
01-05 17:43:14.096: W/System.err(2371): Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f050011, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
01-05 17:43:14.156: W/System.err(2371): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
01-05 17:43:14.166: W/System.err(2371): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
01-05 17:43:14.166: W/System.err(2371): ... 18 more
01-05 17:43:14.186: D/AndroidRuntime(2371): Shutting down VM
01-05 17:43:14.186: W/dalvikvm(2371): threadid=1: thread exiting with uncaught exception (group=0x41465700)
01-05 17:43:14.256: E/AndroidRuntime(2371): FATAL EXCEPTION: main
01-05 17:43:14.256: E/AndroidRuntime(2371): java.lang.NullPointerException
01-05 17:43:14.256: E/AndroidRuntime(2371): at com.main.whereismyfriend.CustomMapFragment .onResume(CustomMapFragment .java:96)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.support.v4.app.Fragment.performResume(Fragment.java:1521)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:963)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.os.Handler.handleCallback(Handler.java:730)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.os.Handler.dispatchMessage(Handler.java:92)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.os.Looper.loop(Looper.java:137)
01-05 17:43:14.256: E/AndroidRuntime(2371): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-05 17:43:14.256: E/AndroidRuntime(2371): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 17:43:14.256: E/AndroidRuntime(2371): at java.lang.reflect.Method.invoke(Method.java:525)
01-05 17:43:14.256: E/AndroidRuntime(2371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-05 17:43:14.256: E/AndroidRuntime(2371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-05 17:43:14.256: E/AndroidRuntime(2371): at dalvik.system.NativeStart.main(Native Method)

主要 Activity :

public class MainActivity extends FragmentActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

...

CustomMapFragment fragment = new CustomMapFragment (getApplicationContext(),this);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment ).commit();

...
}

自定义 map fragment :

public class CustomMapFragment extends SupportMapFragment implements ConnectionCallbacks,OnConnectionFailedListener,LocationListener  {

private LocationClient locationClient;
private LocationRequest locationRequest;
private GoogleMap map;
FragmentActivity activity;
private Context context;
View view;

public CustomMapFragment (Context context,FragmentActivity activity){
this.context = context;
this.activity = activity;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

super.onCreateView(inflater, container, savedInstanceState);

try {
view = inflater.inflate(R.layout.map_layout, container,false);


SupportMapFragment suppFragManager = (SupportMapFragment)activity.getSupportFragmentManager().findFragmentById(R.id.map);
map = suppFragManager.getMap();

locationClient = new LocationClient(context,this,this);

locationRequest = LocationRequest.create();
locationRequest.setInterval(9000);
locationRequest.setFastestInterval(900);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

return view;
} catch (Exception e) {
Log.d("ERROR", e.getMessage());
e.printStackTrace();
}

return null;

}

...

map 布局:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />

安卓 list 文件:

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


<permission
android:name="com.main.whereismyfriend.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.main.whereismyfriend.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">

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

...

</application>

注意:我在这个类中使用 android.support.v4 库

最佳答案

public class CustomMapFragment extends SupportMapFragment

所以,CustomMapFragment 是一个 SupportMapFragment...

view = inflater.inflate(R.layout.map_layout, container,false);

...您正试图将 另一个 SupportMapFragment 膨胀到其中。

这不会很好地工作。

Either CustomMapFragment 扩展 SupportMapFragment(并删除其 onCreateView() 加上 map_layout.xml ) 使用您的map_layout.xml。不要两者都做。

关于android - SupportMapFragment - 二进制 xml 文件行 #2 : Error inflating class fragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20940572/

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