我正确地按照每一步在xamarin工作室开发应用程序,如(https://developer.xamarin.com/guides/android/getting_started/hello,android/hello,android_quickstart/)所示 但是,在构建解决方案后,有11个错误 1.'找不到类型或命名空间名称 Android 。(您是否缺少using指令或程序集引用?)' 2.'找不到类型或命名空间名称活动。(您是否缺少using指令或程序集引用?)' 3.'找不到类型或命名空间名称 Bundle 。(您是否缺少using指令或程序集引用?)' 如何摆脱这些错误?请帮忙
这是代码---
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace PhoneWord
{
[Activity (Label = "PhoneWord", MainLauncher = true, Icon ="@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our UI controls from the loaded layout:
EditText phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
Button callButton = FindViewById<Button>(Resource.Id.CallButton);
// Disable the "Call" button
callButton.Enabled = false;
// Add code to translate number
string translatedNumber = string.Empty;
translateButton.Click += (object sender, EventArgs e) =>
{
// Translate user's alphanumeric phone number to numeric
translatedNumber = Core.PhonewordTranslator.ToNumber(phoneNumberText.Text);
if (String.IsNullOrWhiteSpace(translatedNumber))
{
callButton.Text = "Call";
callButton.Enabled = false;
}
else
{
callButton.Text = "Call " + translatedNumber;
callButton.Enabled = true;
}
};
// 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++);
};*/
}
}
}
谢谢
答案 0 :(得分:1)
您的项目命名空间似乎包含MyProject.Android
中的Android。这主要是你描述的原因。
更改命名空间,它应该可以正常工作。
答案 1 :(得分:0)
我通过添加对
的引用解决了该问题Mono.Android.dll
位于:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.1\