[英]Error CS0234 The type or namespace name 'Android' does not exist in the namespace 'Xamarin.Forms.Platform
When I create a new blank cross-platform project in Visual Studio 2017 I get about six errors.当我在 Visual Studio 2017 中创建一个新的空白跨平台项目时,我收到大约六个错误。 All on 'MainActivity.cs' page.
全部在“MainActivity.cs”页面上。 I'm running VS2017 that updated to support Core 2.1.
我正在运行更新为支持 Core 2.1 的 VS2017。 I'm not sure what I need to install or change to fix this.
我不确定我需要安装或更改什么来解决这个问题。
I'm using我正在使用
C:\\Program Files\\Java\\jdk1.8.0_171
C:\\Program Files\\Java\\jdk1.8.0_171
C:\\Program Files (x86)\\Android\\android-sdk
C:\\Program Files (x86)\\Android\\android-sdk
and under tools and extensions, everything is up to date.在工具和扩展下,一切都是最新的。
namespace HelloWorld.Droid
{
[Activity(Label = "HelloWorld", Icon = "@mipmap/icon", Theme =
"@style/MainTheme", MainLauncher = true, ConfigurationChanges =
ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity :
global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
}
}
errors(I get these errors every time I create a blank project)错误(每次创建空白项目时都会收到这些错误)
Error CS0103 The name 'LoadApplication' does not exist in the current context Error CS0234 The type or namespace name 'Android' does not exist in the namespace Error CS0115 'MainActivity.OnCreate(Bundle)': no suitable method found to override Error CS0103 The name 'ToolbarResource' does not exist in the current context Error CS0103 The name 'TabLayoutResource' does not exist in the current context Error CS0234 The type or namespace name 'Forms' does not exist in the namespace 'Xamarin.Forms'
错误 CS0103 当前上下文中不存在名称“LoadApplication” 错误 CS0234 命名空间中不存在类型或命名空间名称“Android” 错误 CS0115“MainActivity.OnCreate(Bundle)”:找不到合适的方法来覆盖错误 CS0103当前上下文中不存在名称“ToolbarResource”错误 CS0103 当前上下文中不存在名称“TabLayoutResource”错误 CS0234 命名空间“Xamarin.Forms”中不存在类型或命名空间名称“Forms”
I'm new to Xamarin and I tried to add references to my project but I'm not sure which of the 3 projects to add references or what references I need.我是 Xamarin 的新手,我尝试添加对我的项目的引用,但我不确定要添加引用的 3 个项目中的哪一个或我需要哪些引用。
In the end, doing the below solved the issue:最后,执行以下操作解决了问题:
what I did was went to help in VS2017
and updated to 15.9.6
and it recommended an update to Android SDK
.我所做的是去帮助
VS2017
并更新到15.9.6
并推荐更新到Android SDK
。 So I updated it all and cleaned and rebuild project and that fixed the issue.所以我更新了所有内容并清理并重建项目并解决了问题。 When I first ran the project it told me some
Android references need updating
and I updated from the error list and in the NuGet
panel.当我第一次运行该项目时,它告诉我一些
Android references need updating
,我从错误列表和NuGet
面板中进行了更新。 And it worked它起作用了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.