我在Xamarin.Android中编写了一个应用程序。我有另一个核心应用程序,我存储了一些类和视图,我想从它继承一个Activity。在构建项目时一切都很顺利,但在启动应用程序时,它会引发异常。 来自基类的片段:
namespace Company.Core.Android
{
public class MenuableFragmentActivity : SlidingFragmentActivity
{
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
SetSlidingActionBarEnabled(true);
// Set our view from the "main" layout Company.Core.Android.Resource
Console.WriteLine("runs correctly until this point");
SetBehindContentView (Company.Core.Android.Resource.Layout.menu_main);
继承应用程序中的MainActivity如下所示:
using Company.Core.Android;
namespace Company.Bite.Android
{
[Activity(Label = "App.Android", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity :MenuableFragmentActivity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
var something = Core.Android.Resource.Layout.menu_main;
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
}
}
有趣的是,some变量可以很容易地从核心到达资源,但是当我部署应用程序时,会抛出异常(该ID属于menu_main):
我认为应用程序在自动生成的Resources.Designer.cs文件中搜索menu_main,而不是搜索完全限定的名称(Company.Core.Android ...) 我坚持这个,有谁知道,如何解决这个问题?
提前致谢