【发布时间】:2019-07-12 00:38:14
【问题描述】:
我收到一个错误提示
java.lang.IllegalArgumentException:未找到 id 0x7f0e00a7 的视图 (com.jvlapps.myapp:id/linearLayout1) 用于片段 ParamMapFragment
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linearLayout1">
<com.google.android.gms.ads.AdView
android:id="@+id/bannerAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@+string/AdMob_TEST_Unit_Id" />
<fragment
android:name="GetMeThere.MainMenuFragment"
android:id="@+id/MainMenuFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
这里是 ParamMapFragment.cs:
public class ParamMapFragment : Fragment
{
public string AgencyName => Arguments.GetString("current_agency", "None");
public ParamMapFragment() { }
public static ParamMapFragment NewInstance(string currentAgency)
{
var bundle = new Bundle();
bundle.PutString("current_agency", currentAgency);
return new ParamMapFragment { Arguments = bundle };
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if (container == null)
{
return null;
}
MapView mapView = new MapView(Activity);
return mapView;
}
}
这是我的 Activity 的 OnCreate:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var agencyName = Intent.Extras.GetString("current_agency", "None");
var mapFrag = ParamMapFragment.NewInstance(agencyName);
FragmentManager.BeginTransaction()
.Add(Resource.Id.linearLayout1, mapFrag, "main_map_fragment")
.Commit();
}
我已经为此苦苦挣扎了好几个小时。我不知道此时我什至在做什么,或者我的应用程序应该再做什么。我要完成这个应用程序,然后毁灭宇宙。
【问题讨论】:
-
你在哪一行得到这个错误?
-
@Mehmed VS 说“所有线程都在执行外部代码”,所以我没有具体说明。但是 FragmentManager.BeginTransaction().Add... 行是它发生的地方,基于我一次通过一行。
标签: c# android android-fragments xamarin